Android app architecture design 02, androidapp

Source: Internet
Author: User

Android app architecture design 02, androidapp

Ii. Try to place the tool class and BaseActivity in the specified position during the opening process,

DateFormat
Bitmap
Notification
Shared Preference
Environment
Device

III:

2.2 Task Management

The thread is just a mechanism to ensure that the tasks we want to complete do not run in the UI thread (that is, do not block the UI). The completed tasks are the core of our attention. Therefore, we can design, encapsulate the thread so that the user does not feel it is a thread. He only needs to care about what he wants to do.
Here, we can design a "Asynchronous chained call" framework to encapsulate threads. You only need to use it like this:

12345
new TaskManager().next(task1).next(task2).next(task3)..execute();

Here, task 1, task 2, and task 3 are executed sequentially. For example, to access the network and obtain an image, we need three tasks to use TaskManager,

Task1: displays a ProgressDialog.

Task2: access the network and create a bitmap.

Task3: closes the dialog box and displays bitmap.

For more information, see the task. TaskManager class in the CoreLib project.

Note the following for TaskManager:

-Encapsulated threads
Allow callers to focus only on their own business processing
Ensure sequential chained execution of a task
Output of the previous task as input of the next task
Can pause or resume any task


IV:

2.3 Cache Design

-Store objects with large memory usage in the cache, such as bitmap
Implemented using the LruCache class
The AsyncTask class is used to load bitmap
You do not need to manually release the bitmap memory. This operation is risky.
No need to care about the scroll status of AbsListView
For more details about cache, refer to [cache package in CoreLib project].

In this way, there is no need to manually release the bitmap, and this operation is risky because the bitmap has View references. If a View tries to draw a recycled bitmap, an exception is thrown here.

V. 2.4 threads manage threads without message loops:
123456
new Thread(null, new Runnable() {    public void run() {        // Do you works.    }}, "Thread_name_xxx").start();

When to use this thread:

-When you finish one task, the frequency of the task is not high. For example, you can read image data from the SD card.
No need to reuse threads

When using a thread, it is best to add a name to the thread so that the height and tracking can be used.

Threads with message loops:

Such a thread has a message loop. When there is no message in the message queue, this thread will be suspended. To do one thing, you only need to send a message to it.

This is usually used to reuse threads without frequently creating threads. For example, the music player program starts a thread with a message loop to obtain the album pictures of music.

We usually need to create a Handler associated with the message loop of this thread to process messages. Note that this is done in the background thread.


What are the ideas and principles of Android architecture design?

Rlei analyzes the Android Design Philosophy:
After understanding Intent, you can understand the Android philosophy (all applications are equal. For a simple example, apps in iOS need to be implemented by themselves to integrate SNS, such as facebook, twitter, and sina weibo (iOS5 only integrates twitter ); on Android, you only need to broadcast a share content intent. Starting from understanding how Intent works, you can understand how Activity Manager, Package Manager, and Services are important Android components.
In addition, the Binder is a core component of the Android architecture. Android's Intent-based message transmission is decoupled from components/applications. The following basic information is Binder IPC. In this regard, Android is actually a glorious part of the failure to carry forward BeOS and Palm OS 6 (sadly reminded os6.
MVC (Content Provider, Activity, Layout, Adapters) is relatively basic and is not unique to Android.
The abstract of data access by the Content Provider is also interesting. Ideally, the content provider allows the client to access data in a semantic manner using Uris (URIs themselves represent data hierarchies and query conditions ), the structure of the following database table can be changed without affecting the client code. Of course, content provider will be exposed to SQL implementation details by a variety of complex where clauses.
As for Android permission management, it is actually relatively simple. It mainly uses the ready-made Linux security model to isolate processes from each other. API-level permission management is similar to JVM.
Billy Cui focuses on the design of the permission system:
Android permission system is based on Linux, but many control modules are added.
In general, the permission system is divided into the following parts:
1. userid: inherited from linux. For Multiple apps, you can use the same userid through shareuid, which is mainly responsible for directory access permissions, for example, a private directory can only be accessed by the same uid application.
2. installation level: system level or app level, which is determined based on the application installation location. The application installed under system/app is system level, you can obtain more permissions, such as the permission to silently install the application.
3. permission: This is the most important permission control. Generally, developers are mainly engaged in developing applications. the use-permission declared in xml determines whether it has access permissions when accessing the corresponding api or resource, such as the commonly used android. permission. INTERNET.
4. signature: signature is an important part of the Android permission system. For system signature applications, there are some special functions, and shareuid and other features also require the same signature as the basis. In addition, permission often uses signatures when setting/customizing their permissions. For example, only my own applications can access my own public APIs.
In addition, Android has set uid with special features in the uid, such as system/media, which will be used when configuring system-level services.
Dong zhaohui believes that Android is mainly based on the idea of component collocation:
Speaking of the design ideas and principles of the Android architecture, I understand that components are mainly used together. In the user's opinion, all modules or components can be reused and simplified ...... remaining full text>

Learning from a standard framework android app

The sdk contains too many aspects and contains a good project structure package. This is something that cannot be achieved without years of working experience and good learning ability! Haha, so I suggest you do not take it too fast.
 

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.