Understanding of the Android layout and Windows

Source: Internet
Author: User


Number of context instances = Number of Service + activity number + 1 (application corresponding context instance)

Context

1, it describes the information of an application environment, that is, the context.

2, the class is an abstract class.





Application:


When you create a Application object, and the entire app has a application object

Getapplicationcontext () Returns the context of your entire application, whose life cycle is destroyed by the entire application,application after it is destroyed.

Getbasecontext () returns the context specified by the constructor or Setbasecontext () setting (not recommended by Google engineers).


So the life cycle of application is the life cycle of the whole program, and the program completely exits application before it is destroyed.


Activity and view

The relationship between window,activity and view is like this:

in activity, new takes a window, and window (interface) obtains a subclass instance from this Phonewindow subclass. This is a typical composite pattern . Again through

The Phonewindow Setcontentview uses layoutinflater internally to set the view to window.


The feeling is that the activity is the window (interface), the view is displayed in the window layout


This and activity.this


Activity.this's context belongs to the activity, with the same life cycle as the activity, disappearing with the current activity.this.

This is a reference to your current object , where this is placed is the pointer, if the activity is activity, it is equivalent to activity.this, if placed in Onclicllistener () is Onclicklistener ().


Activity in the life cycle of Activity.this is the current page, the current page is destroyed , the activity is destroyed, and this refers to the current object, in the actual development of some need to indicate which activity is the object, Otherwise the compilation does not pass.


Look at the chart between them.







From these graphs you can see that the context is a dozen window (interface), the next level of the interface is application and then the next level is activity, Cointext is the parent class of these classes ,


The same layout view is the parent class of the controls in all layout layouts. They are a management window that displays a management layout.

1, it describes the information of an application environment, that is, the context.

2. The class is an abstract class, and Android provides a concrete implementation class for that abstract class (we'll talk about the Contextiml class later).

Understanding of the Android layout and Windows

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.