Brief Introduction to the activity Startup Process of Android applications

Source: Internet
Author: User

Transferred from:
Http://blog.csdn.net/luoshengyang/article/details/6685853

In the Android system, activity and service are the core components of applications. They are loosely coupled to form a complete application, this is because the application framework layer provides a complete set of mechanisms to help applications start these activities and services, and provides the Binder Mechanism to help them communicate with each other. In the previous article, the android inter-process communication (IPC) mechanism binder briefly introduced and analyzed the learning plan and the principle of the Android system starting the Custom Service Process (startservice) in the new process, we have systematically introduced the Binder Mechanism and service startup process. In this article, we will briefly introduce the activity startup process and subsequent learning plans.

In the Android system, there are two operations that will trigger activity startup. When a user clicks the application icon, launcher will start the main activity of the Application for us; after the default activity of the application is started, it can call the startactvity interface internally to start a new activity. In this way, each activity can start a new activity internally. Through this chain reaction, the activity is started as needed to complete the functions of the application.

Here, we use a specific example to illustrate how to start the activity of the android application. There are two ways to start an activity: explicit and implicit. Implicit startup can make the coupling between activities more loose. Therefore, here, we only focus on the implicit method for starting the activity.

 

Whether you start an activity by clicking the application icon or calling the startactivity interface inside the activity to start a new activity, you must use the activitymanagerservice service process at the application framework layer. In the previous article on how the Android system starts the Custom Service Process (startservice) in the new process, we have seen that the service is also started by the activitymanagerservice process. In the framework layer of Android applications, activitymanagerservice is a very important interface. It not only starts activity and service, but also manages activity and service.

The activitymanagerservice In the Android Application Framework layer starts the activity process as follows:

 

In this figure, activitymanagerservice and activitystack are in the same process, while applicationthread and activitythread are in another process. Among them, activitymanagerservice is responsible for managing the lifecycle of the activity, and activitymanagerservice also uses activitystack to place all the activities in a stack in the order of going first and foremost. for each application, each activitythread contains an applicationthread instance, which is a binder object that communicates with other processes.

The following briefly introduces the startup process:

Step 1. whether you start an activity through launcher or call the startactivity interface inside the activity to start a new activity, it enters the activitymanagerservice process through communication between the binder processes and calls activitymanagerservice. startactivity interface;

Step 2. activitymanagerservice calls activitystack. startactivitymaywait to prepare information about the activity to be started;

Step 3. activitystack notifies applicationthread to start and schedule the activity. Here applicationthread indicates that activitymanagerservice is called. startactivity interface process, for the scenario of clicking the application icon, this process is the launcher, and for the scenario of calling startactivity within the activity, this process is the process of the activity;

Step 4. applicationthread does not execute the actual Startup operation. It calls the activitymanagerservice. activitypaused interface to enter the activitymanagerservice process to see if a new process needs to be created to start the activity;

Step 5. when you click the application icon to start the activity, activitymanagerservice calls startprocesslocked to create a new process, this step does not need to be executed to start a new activity by calling startactivity within the activity, because the new activity is started in the process where the original activity is located;

Step 6. activitymanagerservic calls the applicationthread. schedulelaunchactivity interface to notify the corresponding process to start the activity;

Step 7. applicationthread forwards the activity Startup operation to activitythread. activitythread imports the activity class through classloader and starts it.

In this way, the activity Startup Process of the Android Application is briefly introduced here. In the next two articles, we will refer to the two startup scenarios of the activity, go deep into the source code of the application framework layer and analyze their startup process step by step:

1.
Source code analysis during Android Application startup;

2.
Source code analysis of the startup activity process (startactivity) in the Android Application.

 

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.