1. When we click on the app desktop icon, the desktop Launcher application will call
startActivity—-> startActivityForActivityResult—–> Insrumention(execStartActivity)—> ActivityManagerProxy(startActivity)– > Binder Communication —-> Notify ActivityManagerService.
2.ActivityManagerService does the following when it receives a request from AMP to start the Activity:
A: Check whether the Activity is registered in the androidmanifest.xml manifest file.
B: If it is valid, it will temporarily store the Activity information, use ActivityStack to get the Activity at the top of the stack, and notify the Launcher application to pause the Activity.
C: Check whether the Activity process exists.
2.1. If the Activity is in a process that does not exist
A: Process.start() is called to notify the Zygote Process to fork A new Process via Socket communication.
B: Load the ActivityThread and call main() to initialize it. Thread. Attach (false, startSeq)– >actachApplication()
B1: Check whether the Application exists. If so, directly bind the current process. If not, call Loadapk. makeApplication to create a new Application and bind the current process.
public static void main(String[] args) { Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "ActivityThreadMain"); // CloseGuard defaults to true and can be quite spammy. We // disable it here, but selectively enable it later (via // StrictMode) on debug builds, but using DropBox, not logs. CloseGuard.setEnabled(false); Environment.initForCurrentUser(); // Set the reporter for event logging in libcore EventLogger.setReporter(new EventLoggingReporter()); // Make sure TrustedCertificateStore looks in the right place for CA certificates final File configDir = Environment.getUserConfigDirectory(UserHandle.myUserId()); TrustedCertificateStore.setDefaultUserDirectory(configDir); Process.setArgV0("<pre-initialized>"); Looper.prepareMainLooper(); // Find the value for {@link #PROC_START_SEQ_IDENT} if provided on the command line. // It will be in the format "seq=114" long startSeq = 0; if (args ! = null) { for (int i = args.length - 1; i >= 0; --i) { if (args[i] ! = null && args[i].startsWith(PROC_START_SEQ_IDENT)) { startSeq = Long.parseLong( args[i].substring(PROC_START_SEQ_IDENT.length())); } } } ActivityThread thread = new ActivityThread(); thread.attach(false, startSeq); if (sMainThreadHandler == null) { sMainThreadHandler = thread.getHandler(); } if (false) { Looper.myLooper().setMessageLogging(new LogPrinter(Log.DEBUG, "ActivityThread")); } // End of event ActivityThreadMain. Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); Looper.loop(); throw new RuntimeException("Main thread loop unexpectedly exited"); }Copy the code
2.2. On the AMS server side, the ApplicationThreadProxy (ATP) ApplicationThead proxy class on the server side calls the ScheduleLanuchActivity to start the Activity. Notify ApplicationThread to start the Activity.
2.3.ApplicationThread ——-> The Handler sends a LaunchActivity message to the ActivityThread, which is then called by the ActivityThread
handleLaunchActivity—>performLaunchActivity—->Instrumentation—>newActivity—->callActivityCreate—->callActivity Start– > CallActivityResume. —–>UI rendering complete.