In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the Android application framework layer to create the application process has what characteristics, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
The application process created by the Android application framework layer has two characteristics, one is that the entry function of the process is ActivityThread.main, and the other is that the process naturally supports Binder inter-process communication mechanism; these two characteristics are realized in the process of process initialization. This paper will analyze in detail how to realize these two characteristics in the process of Android application process creation.
The entry function of the application process created by the Android application framework layer is ActivityThread.main, that is, after the process is created, the Android application framework layer will load the ActivityThread class in the process and then execute its main function, which is where the process executes the message loop. How to understand the fact that the application processes created by the Android application framework layer naturally support the Binder inter-process communication mechanism? When we were learning the Binder interprocess communication mechanism of the Android system, we said that it has four components, namely, the driver, the daemon, the Client and the Server. During initialization, the Server component must enter a loop to interact with the Binder driver continuously in order to obtain the request sent by the Client component. For more information, please refer to the source code analysis of the Server startup process in the Android system interprocess communication (IPC) mechanism Binder. However, when we implement the Server component in the Android application, we do not let the process enter a loop to wait for the request of the Client component. However, when the Client component gets the remote interface of the Server component, it can communicate smoothly with the Server component. This is because the Android application process has already started a thread pool to support the interaction between Server components and Binder drivers when it is created, which greatly facilitates the creation of Server components in Android applications.
In the Android application framework layer, the ActivityManagerService component is responsible for creating a new process for the Android application, which is also running in a separate process, but this process is created during system startup. Under what circumstances does the ActivityManagerService component typically create a new process for the application? When the system decides to start an Activity or Service in a new process, it creates a new process, and then starts the Activity or Service in the new process You can refer to three articles: the principle analysis of Android system starting custom service process (startService) in new process, the source code analysis of Android application startup process, and the method and process analysis of Android application starting new Activity in new process.
ActivityManagerService starts a new process from its member function startProcessLocked. Before delving into this process, let's take a look at the sequence diagram of the process creation process, and then analyze each step in detail.
Step 1. ActivityManagerService.startProcessLocked
This function is defined in the frameworks/base/services/java/com/android/server/am/ActivityManagerService.java file:
[java] view plaincopypublic final class ActivityManagerService extends ActivityManagerNative implements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback {. Private final void startProcessLocked (ProcessRecord app, String hostingType, String hostingNameStr) {. Try {int uid = app.info.uid; int [] gids = null; try {gids = mContext.getPackageManager (). GetPackageGids (app.info.packageName);} catch (PackageManager.NameNotFoundException e) {. }. Int debugFlags = 0;. Int pid = Process.start ("android.app.ActivityThread", mSimpleProcessManagement? App.processName: null, uid, uid, gids, debugFlags, null); } catch (RuntimeException e) {. }}. }
It calls the Process.start function to start creating a new process for the application. Note that it passes in a * * parameter of "android.app.ActivityThread", which is the Java class to be loaded when the process is initialized. After loading this class into the process, it will take its static membership function main as the entry point of the process, as we will see later.
Thank you for reading this article carefully. I hope the article "what are the characteristics of the application process created by the Android application framework layer" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.