Android development APP process start principle

1.) First, when the Android system starts, it will start an application management service PackageManagerService. This service is mainly started by the SystemServer component, as well as the ActivityManagerService service. But through the source code, you will find that BroadcastQueue, ProviderMap, ActiveServices, and ActivityStackSupervisor are also initialized in the constructor of ActivityManagerService. I believe everyone has guessed it. This service is used to manage the four major components of Android, and the PackageManagerService service is used to analyze Apk, in fact, the main analysis is the AndroidManifest.xml file to obtain application-related information (such as: Activity, Service, BroadcastReceiver, Content Provider, etc.) to complete the application installation process. If we want to see these applications on the Android desktop, we also need a Home application, responsible for taking these installed applications out of the PackageManagerService service and displaying them on the desktop in a friendly way, for example, In the form of a shortcut icon. In the Android system, the Home application that is responsible for displaying the installed applications on the desktop is the Launcher.

2.) The icon icon (shortcut icon) application on the desktop is managed by Launcher (DEFAULT, HOME, PREFERENCE, LAUNCHER, BROWSABLE browser, GADGET embedded non-desktop) to manage and start the App, click the desktop icon icon to trigger the Launcher The onItemClick event notifies the ActivityMangerService (all activity stewards) to start the MainActivity of the current program (through the current application package name + the current location of the current location of the main Launcher Activity). If it belongs to the unstarted state, then notify to create a process (uid + process attribute combination) for the program, import the android.app.ActivityThread class through Process.start(), and execute its main function:

1. Create and bind Looper objects in the main function of the process;

2. Then create an instance of ActivityThread and call its attach function to start ActivityMangerService call attachApplication to pass parameters ApplicationThread type Binder object (mAppThread) inter-process communication to enter the ApplicationThread process to create Application, then ApplicationThread scheduling scheduleLaunchActivity is MainActivity, and then use the Handler message mechanism to start Activity scheduling The attach method creates the root container of PhoneWindow, parentContent (DecorView) and calls the onCreate method setContentView through source code analysis, namely parentContent.addView, and then ApplicationThread schedules scheduleResumeActivity, which is the onResume life cycle of MainActivity, or starts by Handler message mechanism to add the container to the window wm .addView (parentView, 1) The window itself has a RootView, and then the root View starts to call requestLayout to schedule performTraversals (execute a traversal of performMeasure, performLayout, performDraw, which is the View control layer measurement, layout, and drawing) and the next life cycle is also executed in sequence Up

3. Enter the loop message loop.

Guess you like

Origin blog.csdn.net/xhf_123/article/details/78990882