Android app installation and launcher boot mechanism

Source: Internet
Author: User
Tags message queue

The following extracts from the old Luo's Android tour blog, is the old Luo's blog on the android underlying principles of an abstract knowledge summary (if there is an erroneous welcome point) (Invasive deletion):
http://blog.csdn.net/luoshengyang/article/details/8923485
http://blog.csdn.net/luoshengyang/article/details/12957169

Organize by Doing

         During the boot process, the Android system launches an application management Service Packagemanagerservice, which scans the system for specific directories and finds the application files inside files with the apk suffix , and then parse the files (in fact is thatparsing the application configuration file Androidmanifest.xmlProcess and get information about the application from the inside, such as getting the application's component activity, Service, broadcast receiver, and content provider) to get information about the application, Complete The installation of the application process.         throughActivitymanagerservicethis service,we'll be able to do it properly in the system.Use these applicationsup.
    • Packagemanagerservice is responsible for installing the system application:
  1. The zygote process starts in the Android system during the boot process . Systemserver Components , The systemserver component starts the packagemanagerservice service, Activitymanagerservice Service and so on .
  2. Packagemanagerservice service startup process : Create a Packagemanagerservice service instance , Span style= "line-height:1.6;" > add this service to ServiceManager (
  3. packagemanagerservice class, start the process of installing the application : call The Scandirli function scans the APK files in five directories on a mobile device (  /system/framework,  /system/app,  /vendor/app, /data/app,  /data/app-private ) , with the apk as the suffix , then call the Scanpackageli function to parse and install :
  4. First, a Packageparser instance is created for this apk file, and then the parsepackage function of this instance is called to parse the apk file ( This function will finally call another version of the Scanpackageli function to save the parsed application information in the Packagemanagerservice. See later ):
  5. Each apk file is an archive file, which contains the android application configuration file Androidmanifest.xml, which is mainly to resolve this configuration file. Once the profile is obtained from the APK archive, the application is parsed by calling another external version of the Parsepackage function: parsing the individual tags in the androidmanifest.xml file , such as the parsing of application tags, this is done by calling the Parseapplication function.
  6. Once the parsing is complete, a layer of layers returns, invoking another version of the Scanpackageli function, which puts the package, provider, service, Information such as receiver and activity is stored in the Packagemanagerservice service (stored in mpackages, Mactivities, Mreceivers, Mservices, and other member variables ( HashMap type))
    • These applications are just equivalent to registering in the Packagemanagerservice service, if we want to see these apps on the Android Desktop, There is also a home application (the default home app for Android is launcher), which is responsible for removing these installed applications from the Packagemanagerservice service and displaying them in a friendly manner on the desktop. For example, in the form of a shortcut icon:
  1. After the application in the system is installed, the Systemserver component then launches the home application via activitymanagerservice launcher
  2. Activitymanagerservice.starthomeactivitylocked () creates a intent of type Category_home, And then through the Intent.resolveactivityinfo function to the Packagemanagerservice query category type is home activity
  3. .
  4. handle loading an application as a message : Sworker (Handler) puts a message in the message queue by its post, The system then invokes the run function of the parameter Mloadertask (loadertask type) passed in to handle the message: Calling the Loadandbindallapps member function, since the application has not yet been loaded, The mallappsloaded here is false, so call Loadallappsbybatch, construct a category_launcher type of intent , Mcontext.getpackagemanager () obtains packagemanagerservice interface, Through this packagemanagerservice.queryintentactivities interface to Retrieve all ACTION types to Intent.action_ MAIN, and the category type is Intent.category_launcher's activity (when the Packagemanagerservice is started, the application in the system is parsed again, The parsed activity is then saved in the Mactivities member variable, where the mactivities variable's queryintent function returns the activity that matches the condition intent, This is where the ACTION type is intent.action_main, and activity with category type Intent.category_launcher is returned
  5. Allapps2d.setapps , setapps Call addapps function to get , and with these applicationinfo instances, all the applications on the system can be displayed on the desktop. here it is. The system default home Application Launcher the application in Packagemanagerservice: When we click the Home button, launcher.onclick function call the Showallapps function to display the application icon < Span style= "color: #0000ff;" > The application that you just loaded is displayed as an icon .
  6. When these application icons are clicked , they respond to the Allapps2d.onitemclick function and then call the Launcher.startactivitysafely function to start the application



Android app installation and launcher boot mechanism

Related Article

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.