On the design of Android architecture

Source: Internet
Author: User

So far, Android Development has no recognized or unified development Framework on the Web or in the community, and many frameworks are based on the encapsulation of methods. Today in this talk about the understanding of Android development for two years, mainly is the understanding of the mind, I hope to help everyone.

I think that Android development can summarize the architecture design from two aspects, where the implementation only makes a statement:

One, is that most people's design ideas, the encapsulation of methods.

Here I design the project according to the habit of development:

1. http: Network request method Encapsulation. It is recommended that threading +handler mode be used to separate the Get method in HTTP and post two request mode, and to use post for normal operation logic to facilitate the encapsulation, encryption and security of the data. For getting pictures, this video can be directly take doctrine via a URL with get, fast and uncomplicated.

2. Thread: Since the HTTP to take the thread of the way the natural thread management is a focus, it is recommended that the entire application of the unified management of threads, according to the characteristics of the thread pool packaging multi-threaded and single-threaded, each time to enable threads to the thread pool to fetch, so the total number of threads in the app, The size of the memory footprint is basically under control.

3. Download: Download the apk or manage the download of the image and video. During the combination of multi-threading, soft referencing, local storage, memory storage can be multithreaded under the picture. Download image processing Results There are two ways a direct delivery display ImageView display, but this way to the return of the image processing is not very convenient, so we suggest that the return of the way, the return of the object, the need to return to the page processing to add back the event.

4. Upload: Upload files, pictures, videos, etc., this upload can be done on the file compression and upload will be better.

5. DAO: Operation of database, build table, version control, add data, increase, delete, change and check data.

6. File: Operations on files.

7. Utils: Tool class.

8. Exception: Exception class, the exception class is mainly based on the HTTP request to return the error code to parse, as well as the project to run some details to capture.

9. The package of the Log:log must be implemented in three kinds, a: development and debugging; B: Error log is saved locally at publish time; C: Publishing is a necessary error logging send server.

Bean: Data Encapsulation bean. The pass-through data is recommended by the bean using JSON and Gson to convert each other.

Second, it can be designed from the business logic processing based on data and data.

The above is the majority of the packaging ideas, mainly for the method of encapsulation, the following is to say that the above package integration into the actual project business approach, mainly for the business of packaging, where the general direction of the main application of two design patterns: Intermediary mode, MVP mode. In the meantime, the Factory mode, simple interest mode, template mode, observer pattern and so on are used extensively.

The whole idea is:

Daorest,httprest,filerest: These packages mainly encapsulate the interface between the app and each channel, can be added according to the actual project requirements, there is no implementation method, all the classes are all interfaces.

Mediator: Intermediary, if the interaction in the ordinary way we use A,B,C instead of three different interfaces, if there is a page v need to use these three sources, then there will be V and a interaction, V and B,v and C 22 interaction, if there is a complex relationship between V and AB interaction and so on, Such an interaction is like a net without rules, which is difficult to understand. When we use an intermediary, the problem will be greatly improved, we introduce an intermediary m at this time ABC is integrated into M, ABC's relationship with V no matter how complex, by the internal integration, and finally by M Unified Issue v interaction, at this moment the relationship is very clear. V and ABC no matter who needs change will not affect each other, m acts as a mediating relationship so the intermediary mode is called the mediator pattern.

Presenter: This is the P in MVP mode. Many people say that Android is not a good way to differentiate the MVC pattern, because the activity contains both V and C, in fact, the real Android v layer I feel should be the XML layer, but the XML layer can not dynamically change the data. So simply take a step back and let the activity also be our only V-tier, when the MVP is born. The MV is the same as the MV in MVC, and P is the layer we added to deal with the business in activity, and we named him presenter. P The main role of the original activity in all the data processing moved to the P-layer, so that the activity becomes a pure v. Specific implementation of the method can be consulted: http://blog.csdn.net/zhouyinhui/article/details/4614474

View:activity implementation layer.

The final summary of the project directory also probably came out, here is the main introduction is the framework of the MEDIATOR+MVP model and the general realization of the idea, including a lot of details, such as each layer of business interface needs abstracts restrictions, management needs to use Factory mode, The way the code is implemented requires a template, and the change in view layer state requires the observer pattern and so on. It takes a lot of effort to write a framework that requires constant refactoring. Oh, yes, just a few catalogs to fill.

The 15.service:android service does not close with the app's shutdown. Are often turned off by third-party software.

16.broadcase: Broadcast, and then notify the activity between the state of the time is very useful, similar to the observer pattern.

Hope that the written for everyone to help, learn from each other!



On the design of Android architecture

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.