1. The relationship between activity, window, and view in Android ( metaphor ):
Activity like a Craftsman (Control Unit), window like Windows (Load model), view like window grilles (Show view)
Layoutinflater like scissors, the XML is configured like a window-grilles drawing.
2. Detailed:
Activity is the carrier of an Android application that allows users to create a user interface on it, and provides APIs for users to handle events such as Onkeyevent, Ontouchevent, and so on. and maintain the life cycle of the application. The activity itself is a huge carrier that can be understood as the carrier of the application and will not work if the wood has a activity,android application. It can also be understood as an entry point for Android apps. Acivity instance objects are maintained by the system. The system service Activitymanager is responsible for maintaining the instance object of the activity and maintaining its status information based on the running state.
When we call Acitivity's Setcontentview method, we are actually invoking the Setcontentview method of the Window object, so we can see that the rendering of the interface in activity is actually given to the Window object. If you draw a class diagram, you can see that the activity aggregates a Window object.
In this method, first create a decorview,decorview is an expanded Framelayout class, which is the root view of all windows. The Setconctentview that we call in the activity is put into the decorview. This is the aggregation relationship of our class diagram as follows:
Activity--->Window--->decorview
After the activity is created, the system calls its attach method, adds it to the activitythread, and creates a Window object in the Attach method. The Window object is an abstract class. Be aware that the Window object is created and the wood has a decor object created. The user invokes Setcontentview in the activity and then calls the window's Setcontentview, which checks to see if Decorview exists, creates a Decorview object if it does not exist, and then puts the user's own view Added to the Decorview.
Call Wm.addview (decor, L) in Activitythread, add it to the Mviews of Window Manager proxy, and create a decor for the viewroot view. Viewroot is responsible for coordinating Decorview and WindowManager Direct mapping and event processing. The simple point is that Decorview is the root of all client view, window Manager proxy creates a Viewroot and window Manager service for this Decorview
We can take a look at the implementation of Decorview, which is an inner class of Phonewindow. The implementation is simple, it contains a gray title bar by default, and a blank area underneath the title bar is used to place the user view when the user calls Setcontentview and to pass the event.
3. Detailed reference:
http://blog.csdn.net/chujidiy/article/details/7820451
The relationship between activity, window, and view in advanced Android Note 08:android