Android app startup process--launcher Source analysis

Source: Internet
Author: User

When we click on an application icon in the Launcher interface, we start a program, so what happens to this process? Let us follow launcher source code to analyze it.

First on the flowchart:

650) this.width=650; "Src=" http://img.blog.csdn.net/20140509134103500?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqva2luym9z/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Southeast "alt=" Southeast "/>

STEP1, tracking launcher from the source we can find launcher is actually a program, it inherits from the activity. Locate the OnCreate () method in the file, and the code snippet is as follows:


protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Launcherapplication app = ((launcherapplication) getapplication ());        Mmodel = App.setlauncher (this);        Miconcache = App.geticoncache ();        Mdragcontroller = new Dragcontroller (this);        Minflater = Getlayoutinflater ();        Mappwidgetmanager = Appwidgetmanager.getinstance (this);        Mappwidgethost = new Launcherappwidgethost (this, appwidget_host_id);        Mappwidgethost.startlistening ();        if (profile_startup) {android.os.Debug.startMethodTracing ("/sdcard/launcher");        } loadhotseats ();        Checkforlocalechange ();        Setwallpaperdimension ();        Setcontentview (R.layout.launcher);        Setupviews ();        Registercontentobservers ();        Lockallapps ();        Msavedstate = savedinstancestate;        Restorestate (msavedstate);        if (profile_startup) {android.os.Debug.stopMethodTracing ();      }  if (!mrestoring) {            Mmodel.startloader (this, true);}

Find the key section, which is labeled red code above. Mmodel is an object of type Launchermodel, next we trace the Launcermodel.java file.



Step2, ' Launchermodel is a broadcastreceiver, here we first enter the Startloader (context context, Boolean islaunching) method.

650) this.width=650; "Src=" http://img.blog.csdn.net/20140509135622343?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqva2luym9z/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Southeast "alt=" Southeast "/>

Loadertask implements the Runnable interface, and then we find the run () method of the implementation class, and the code snippet is as follows:

650) this.width=650; "Src=" http://img.blog.csdn.net/20140509140121828?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqva2luym9z/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Southeast "alt=" Southeast "/>

The information code snippet for reading the main activity of each application in the system is as follows:

650) this.width=650; "Src=" http://img.blog.csdn.net/20140509140637968?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqva2luym9z/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Southeast "alt=" Southeast "/>

Step3, when we click the application icon, the corresponding method to execute is the onclick () method in Launcher.java, whose code is as follows:

650) this.width=650; "Src=" http://img.blog.csdn.net/20140509141017421?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqva2luym9z/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Southeast "alt=" Southeast "/>650" this.width=650; "src=" http://img.blog.csdn.net/20140509141234218?watermark/2/ text/ahr0cdovl2jsb2cuy3nkbi5uzxqva2luym9z/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Southeast "alt=" Southeast "/>

To this on the application of the start-up process analysis is over, welcome to the Netizen's correction and suggestions, with its common progress.


This article is from the "Fukung-programming Technology" blog, so be sure to keep this source http://kinbos.blog.51cto.com/2092114/1408865

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.