A brief introduction and learning plan for the activity initiation process of the 0-android application

Source: Internet
Author: User


  of source analysis; activity launch process brief introduction and Learning Plan   Source: http://blog.csdn.net/luoshengyang/article/details/6685853


Statement:

RTFSC (Read the Fucking source code) is Linus's famous saying, is also an important means of learning it technology. The best way to learn Android is to system analysis of Android, the source of the Android system, CSDN analysis of the old Luo is the most systematic one. But Lao Luo's analysis of the source of the blog, there are a few good enough:

1. Too much nonsense, may consider too many small white readers, can understand.

2. The results of the analysis are generally a textual form in the blog post, for some of the needs of the user, the author will analyze the results ahead of time.

3. Lao Luo blog Some will not all the place, the author has added, suggest readers read Lao Luo's blog

4. This blog more to supervise their own study-oriented, need crossing supervision, in order to continue.

5. Each article shows the source of the article, respecting Lao Luo's hard output, I'm just a two-time propagator



Lead:

in theAndroidin the system, activity and service are the core components of the application, and they are combined in a loosely coupled fashion to form a complete application, thanks to the application framework layer providing a complete set of mechanisms to assist the application in initiating these activity and service , as well as providing binder mechanisms to help them communicate with each other. In the previous articleAndroid interprocess communication (IPC) Mechanism Binder Brief introduction and Learning Planand theThe principle analysis of the Android system starting the custom service process (StartService) in the new process, we have systematically introduced the binder mechanism and the start-up process of the service, and in this article, briefly introduce the activity initiation process and the follow-up learning Plan.


Brief introduction:

In an Android system, there are two actions that can cause activity to start

1. When a user clicks on an application icon, Launcher will start the application's main activity for us, and when the application's default activity starts up,

2. It can also initiate new activity internally by invoking the Startactvity interface, and so on, each activity can start a new activity internally. Through this chain reaction, activate the activity on demand to complete the functionality of the application.

android system to start the custom service process (StartService) in a new process analysis

The process of starting activity in Activitymanagerservice in the Android application framework layer is roughly as follows:

1. Activitymanagerservice and Activitystack are located in the same process, while Applicationthread and Activitythread are in another process.

2. AMS is responsible for managing the life cycle of the activity, and AMS also uses Activitystack to put all the activity in a stack in the FILO order;

3. For each application, there is a activitythread to represent the main process of the application,

4. Each activitythread contains a Applicationthread instance, which is a binder object responsible for communicating with other processes.


The following is a brief introduction to the startup process:

Step 1. Start a new activity either through launcher, or by invoking the StartActivity interface inside the activity. All through the binder interprocess communication into the activitymanagerservice process, and call the Activitymanagerservice.startactivity interface;


Step 2. AMS calls Activitystack.startactivitymaywait to prepare information about the activity to be started;

Step 3. Activitystack notify Applicationthread To do activity start scheduling, The Applicationthread here represents the process of invoking the Activitymanagerservice.startactivity interface , which is launcher by clicking on the application icon. , and for a scenario that invokes startactivity within the activity, this process is the process in which the activity resides;

Step 4. Applicationthread does not perform a real boot operation, it enters into the AMS process by calling the Activitymanagerservice.activitypaused interface to see if a new process needs to be created to initiate the activity;

Step 5. For a scenario that launches an activity by tapping the application icon, Activitymanagerservice in this step calls startprocesslocked to create a new process , This step is not required to start a new activity by invoking startactivity within the activity, as the new activity is started in the same process as the original activity;

Step 6. Activitymanagerservic calls the Applicationthread.schedulelaunchactivity interface to notify the appropriate process to perform the activity operation;

Step 7. Applicationthread the action that initiates the activity to Activitythread,activitythread to import the corresponding activity class through ClassLoader, and then start it up.


Brief introduction:    

in this way, the activity initiation process for the Android app is briefly introduced here, and in the next two articles, we'll dive into the source code of the application's framework layer, and analyze their start-up process step-by-day, based on both of the activity's startup scenarios:       

1. Source code Analysis of Android application startup process;
2. Click the desktop icon to start the activity process (startactivity) source code analysis.

3. Call startactivity for source code analysis.



About the Author:
Public Number: Code security
: Banana under Guest QQ log: Https://user.qzone.qq.com/1246264702/blog
Blog Address: http://www.cnblogs.com/jiaoxiake/
Email: [Email protected]
--------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------
Knowledge sharing era, to be a good content provider. --------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------





Null

A brief introduction and learning plan for the activity initiation process of the 0-android application

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.