"Android" Application activity START process Analysis

Source: Internet
Author: User

In the Android system, there are two actions that will cause the activity to start, when a user clicks on the application icon, Launcher will launch the application's main activity for us, and after the application's default activity is started, It can also launch new activity internally by invoking the Startactvity interface, and so on, each activity can start a new activity internally. With this ripple effect, the activity is activated on demand to complete the functionality of the application.

There are two types of activation of activity, one is explicit, the other is implicit, and implicit startup can make the coupling of activity more loosely, so here we only focus on the method of implicitly initiating activity.    A very central point in the Android application Architecture :The main activity does not need to know the presence of the jump activity, i.e. it does not directly ownJumpactivity's interface, but it can tell the application's framework layer through a string, what the name of the activity it will start, the other things will be given to the application framework layer, and, of course, the application framework layer will find its corresponding activity based on this string. , and then start it up. This makes the activity in Android applications very loosely coupled, which makes Android applications highly modular, and facilitates the maintenance and updating of future programs, which is important for large client software. of course, the application framework can find the appropriate activity by name, which needs to be matched by the application itself, which is achieved through the application's configuration file Androidmanifest.xml. Whether you start the activity by tapping the application icon or by calling the StartActivity interface inside the activity, you need to use the application framework layer's Activitymanagerserviceservice process. andThe service is also initiated by the Activitymanagerservice process. In the Android application framework layer, Activitymanagerservice is a very important interface that is responsible for initiating activity and service as well as managing activity and service.   The process of starting activity in Activitymanagerservice in the Android application framework layer is roughly as follows:
  
In this diagram, Activitymanagerservice and Activitystack are in the same process, while Applicationthread and Activitythread are in another process. Among them,
    1. Activitymanagerservice is responsible for managing the life cycle of the activity.
    2. Activitymanagerservice also uses Activitystack to put all the activity in the last-in-first-out order on a stack
    3. for each application, there is a activitythread to represent the main process of the application , and each activitythread contains a Applicationthread instance, which is a binder object responsible for communicating with other processes.
   Here's a brief introduction the process of starting:
  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;
  2. Activitymanagerservice calls Activitystack.startactivitymaywait to prepare information about the activity to be started;
  3. Activitystack notify Applicationthread To do activity start scheduling, The Applicationthread here represents the process of invoking the Activitymanagerservice.startactivity interface, which is launcher for the scenario by clicking on the application icon, and for invoking s within the activity Tartactivity scenario, this process is the process of the activity;
  4. Applicationthread does not perform a real boot operation, It enters into the activitymanagerservice process by calling the Activitymanagerservice.activitypaused interface to see if a new process needs to be created to start the activity;
  5. For a story 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;
  6. Activitymanagerservic calls the Applicationthread.schedulelaunchactivity interface to notify the appropriate process to perform the activity operation;
  7. Applicationthread the action that initiates the activity to Activitythread,activitythread to import the corresponding activity class through ClassLoader, and then start it up.
This gives you a brief introduction to the activity initiation process for Android apps. Reference article http://blog.csdn.net/luoshengyang/article/details/6685853

"Android" Application activity START process Analysis

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.