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