Android notes: App modularity and engineering extension applications _android

Source: Internet
Author: User

1. Demand
A reasonable layered architecture is one of the most common modular ideas, whether in. NET or Java platforms.
Dll,jar documents are popular everywhere.
One day, the TX team and I said, we are going to do Android on the three-forum client, a news forum, a literary forum, a music forum. Except for the data, the interface is not the same as the few modules.
The jar was the first thing I thought of, but shared jar files couldn't easily share resources or overwrite resources.
And we will not be silly to do three of the client alone, it will not be silly to do 3 clients and then silly copy3, in turn, modify it.

2. The question
How do you develop a shared framework in the Android project that can share resources, code, but also expand?

3. Use hard coding to judge
Someone has proposed a scheme to judge in code:

Copy Code code as follows:

if (news forum) {
Load a news forum resource
Execute a news forum code
Show the effect of a news forum
}else if (literary forum) {
Loading the resources of the Literature forum
Code to execute a literary forum
Show the effect of the literary forum
}else if (music forum) {
Load the resources of the Music forum
Execute the Music forum code
Show the effect of a music forum
}
PS: This is a very helpless way, the code ugly, poor scalability, there is no better way?

4. Separate project with Android library
The Android Library offers the concept of a library similar to other platforms, which not only provides common code but also shared resources and overwrite resources.
The Android library uses engineered particles to invoke its engineering, actually referencing its code, and then generating the r.java and the resources needed for the main project, eliminating the resources covered in the library. The library in which the androidmanifest.xml can not be reused, that is, the main project must redefine Androidmanifest.xml, this is also easy to understand, Androidmanifest.xml is a project configuration file, generally do not have a shared library of universality.
The steps are as follows:
The first step: new Android Project Common.
The second step: Right key Common, select Properties, on the Android tab, select "Is Library", the following figure.

The third step: new main Engineering News forum Tianxianews.
The fourth step: Right Key Tianxianews, select Properties, on the Android tab, click Add, select Common. The following figure.
Check out the final engineering structure:
At the moment, the common project became a seamless part of the Tianxianews project.
We expand the Tianxianews project's Gen directory:

Eclipse in order to generate two R.java, one is common engineering, a tianxianews project, but the content is the same, the benefit is: R.java inside content includes two engineering resources, first, tianxianews project through R.java can call to COM Mon The resources of the project; Secondly, if there is a apk resource, the Tianxianews project covers the resources of common project, As with two R.java content, the resources in the R.java called by the common code actually call Tianxianews resources, similar to the concept of object-oriented inheritance.
We can also create another new Tianxiamusic,tianxialiterature project, all quoted common, so that we can share common three projects, so that we can only in common a project development.
Here, the specific use of the steps I do not have screenshots out, mainly no technology, there is nothing to say, is two words: cover.

5. Summary
The Android Library provides a good tool or approach for Android modularity and engineering expansion. As the project grows, the need for resource sharing, modularity and expansion is becoming more and more prominent, which not only removes the ugliness of the code, but also reduces the amount of development, and brings many benefits. At the same time we can also see that the Android is immature, they provide for our large projects are still too few, this may also originate from the mobile phone platform itself limitations, we look forward to the Android market more powerful, the technology to more robust.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.