Android Troubleshooting Points

Source: Internet
Author: User

I. Overview

This article mainly answers some problems which are worth studying in the course of studying and working in peacetime.

Two. Questions

when was the 1.DecorView created?
It was created in the Generatedecor of Phonewindow.

protectedgenerateDecor() {        returnnew DecorView(getContext(), -1);    }

when was the 2.ViewRootImpl created?
is created in the Windowmanagerglobal AddView method.

publicvoidaddViewparams,            Display display, Window parentWindow) {      //省去大量代码        ViewRootImpl root;        null;//省去部分代码            new ViewRootImpl(view.getContext(), display);            ......            }

3.Activity process for loading layouts
Call Setcontentview load layout in activity, Setcontentview finally call Phonewindow Setcontentview method, In this method, the root layout XML file is parsed into view to Decorview, and the parent container with ID Contente is found from the root layout file, and the layout file we specified in Setcontentview is added in the inflate way.

//将我们的布局文件添加到mContentParent中,这个mContentParent是根布局中id为content的一个FrameLayout        mLayoutInflater.inflate(layoutResID, mContentParent);

when 4.Window objects are created
In the Attach method of activity

final void attach (context context, Activitythread Athread, Instrumentation instr, IBinder token, int ident, Application application, Intent Intent, activityinfo info, charsequence title, Activity parent, String ID, nonconfigurationinstances lastnonconfigurationinstances, Configuration config) {Attachba Secontext (context);Mfragments. Attachactivity(this, mcontainer, NULL);Create Window Object Mwindow = Policymanager. Makenewwindow(this);Mwindow. Setcallback(this);Mwindow. Getlayoutinflater(). Setprivatefactory(this);if (info. Softinputmode! = WindowManager. Layoutparams. SOFT_input_state_unspecified) {Mwindow. Setsoftinputmode(Info. Softinputmode);} if (info. Uioptions!=0) {Mwindow. Setuioptions(Info. Uioptions);} Muithread = Thread. CurrentThread();.....        }

when 5.Application objects are created
In the Newapplication method of instrumentation

  publicnewApplication(ClassLoader cl, String className, Context context)            throws InstantiationException, IllegalAccessException,             ClassNotFoundException {        return newApplication(cl.loadClass(className), context);    }

where is the starting point for 6.View drawing
The Performtraversals method of Viewrootimpl

privatevoidperformTraversals//省去海量代码 performMeasure(childWidthMeasureSpec, childHeightMeasureSpec);//省去部分代码//省去大量代码  performDraw();  .....  }

the 7.startActivity process
StartActivity will eventually call Startactivityforresult

 public   void  startactivityforresult  (Intent Intent, int  Requestcode, Bundle options) {if  (mparent = =                     Null ) {Instrumentation.activityresult ar = minstrumentation.execstartactivity ( this , Mmainthread.getapplicationthread (), Mtoken, t            His , intent, requestcode, options); if  (AR! = null )                    {Mmainthread.sendactivityresult (Mtoken, Membeddedid, Requestcode, Ar.getresultcode (),                    Ar.getresultdata ()); ....                    }

The actual call is instrumentation's execstartactivity

  PublicActivityresultexecstartactivity(Context who, IBinder Contextthread, IBinder token, Fragment target, Intent Intent,intRequestcode, Bundle options) {//Core function is completed in this whothread, and its internal schedulelaunchactivity method is used to complete activity openingIapplicationthread Whothread = (iapplicationthread) contextthread;if(Mactivitymonitors! =NULL) {synchronized(Msync) {Final intN = Mactivitymonitors.size (); for(intI=0; i<n; i++) {FinalActivitymonitor am = mactivitymonitors.get (i);if(Am.match (WHO,NULL, intent)) {am.mhits++;if(Am.isblocking ()) {returnRequestcode >=0? Am.getresult ():NULL; } Break; }                }            }        }Try{Intent.migrateextrastreamtoclipdata (); Intent.preparetoleaveprocess ();//Where the activity is actually opened            intresult = Activitymanagernative.getdefault (). StartActivity (Whothread, Who.getbasepackagename (), intent, Intent.resolvetypeifneeded (Who.getcontentresolver ()), token, Target! =NULL? Target.mwho:NULL, Requestcode,0,NULL,NULL, options);//Check the result and throw the exceptionCheckstartactivityresult (result, intent); }Catch(RemoteException e) {        }return NULL; }

Iapplicationthread look at the name will know is an interface, we look for implementation class,

publicabstractclass ApplicationThreadNative extends Binder        implements IApplicationThread 
privateclass ApplicationThread extends ApplicationThreadNative 

Applicationthread is used to switch between the various states of activity.

when 8.DecorView is added to the window
In the Makevisible method of activity

 void makeVisible() {        if (!mWindowAdded) {            ViewManager wm = getWindowManager();            wm.addView(mDecor, getWindow().getAttributes());            mWindowAdded = true;        }        mDecor.setVisibility(View.VISIBLE);    }

Android Troubleshooting Points

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.