Activity start entry process source code analysis of (a)

Disclaimer: This article is a blogger original article, reproduced welcome but must indicate the source Thank you! https://blog.csdn.net/dongxianfei/article/details/52238596

1. Background

In the Android system, everyone knows Activity and Service are the core components of the application, we usually use them all the time in the development of Android applications, as do the four components of the Android application, their status is self-evident. Although usually they have been in verse that we use, but you know they start the principle of it? Here definitely someone to ask, not seven methods Activity life cycle it? Then from the onCreate method to begin it?

Yes, you are right to say that the reason is so simple to use Android because they have the perfect package, exposure to only a few specific ways for developers to call, but this is just look at the application layer from the point of view of Android they, then we dig a little deeper, from the Android framework layer to get to know them?

Well, he did not talk much, we began to enter the topic today.

But before you begin today to explain the hope that we first understand some basic knowledge ActivityManagerService of ActivityManagerService and application traffic analysis .

2, Activity start-up mode

Because it is in the framework layer systems perspective to analyze them, so space is also relatively large, so here I am ready to elaborate Activity and Service alone. First we look at Activity, Activity start way we all know it (ps: not what we usually say startActivity and startActivityForResult)? Activity There are two general ways to start:
(1) a user clicks on an application icon, Launcher will be for us the main Activity to launch the application.
(2) Activity Activity by internal startActivity start a new method.
In view There are two ways to start, so I intend to use three blog to explain in detail its start-up mode:
(1) Activity start entry process of source code analysis
(2) Launcher Activity start the process of source code analysis start
(3) Activity start startActivity flow analysis of the source code starts

Today we'll briefly talk about the general process Activity started, so that we have a rough idea, the latter two articles will elaborate.
It usually when developing Android applications Activity should be used for most components, right? So today we will not cite examples, and direct start to analyze their processes.

3, Activity start the process

In fact, whether it is to start Activity by clicking on the application icon, or by calling startActivity method inside Activity to start a new Activity ActivityManagerService service process, both need the help of application framework layer, ActivityManagerService is a very important service, it is not only responsible for starting Activity and Service, also manages them.

Next we look at the Android application framework layer ActivityManagerService start of the general process Activity.

Activity start the process

We start the process simple analysis:

  1. Whether it is to start Activity by Launcher, or internal call startActivity Activity method to start a new Activity through which ultimately inter-process communication Binder ActivityManagerService into the process through, and calls ActivityManagerService.startActivity method.

  2. ActivityManagerService do start calling ActivityStackSupervisor.startActivityMayWait Activity related to the preparation.

  3. ActivityStackSupervisor calls ApplicationThread.schedulePauseActivity method and final call ActivityManagerService.activityPaused way to Pause current view, for application by clicking on the icon, this view is the Launcher, and by calling for internally Activity startActivity, this view is the current Activity.

  4. For the Activity to start by clicking on the application icon, ActivityManagerService calls startProcessLocked here to create a new process, and for calls within the Activity by startActivity to start a new Activity, this step is not required to perform because the new the Activity will be launched in the course of the original Activity is located.

  5. ActivityManagerServic ApplicationThread.scheduleLaunchActivity method call, ready to start operations related to the Activity.

  6. ApplicationThread calls ActivityThread.handleLaunchActivity and method for introducing the final call ActivityThread.performLaunchActivity Activity class by a respective ClassLoader, then it starts up.

Well, to start this whole process of Activity we simply introduced here, then we will conduct a detailed analysis of its two starts.

1, Activity Launcher to start the process of source code analysis starts (two)

2, Activity startActivity start the process of source code analysis start (c)

Guess you like

Origin blog.csdn.net/dongxianfei/article/details/52238596