In the development of the application class, almost every project will be used, it is optimized for the four components run, it is a global box, it can be understood, such as we can store some variables in the application class, can be obtained in other classes, For example, in Class A to store variables in the Appliaction class, and then in Class B can be obtained, but in the application to store static variables, easy to be collected by the system, today is about the relationship between application and context
Take a look at the picture:
It can be seen from the graph that application is a subclass of the context,
From the Java inheritance of the relationship, the function of the subclass must be more powerful than the parent class, we will use the context object in many parts of the project, one method is passed through the method, a method is obtained through the control method, the common layout object in Android can also be obtained, such as: LinearLayout , Relativelayout framelayout, all provide the GetContext () method to get the context object, there is also a direct use in the application class directly,
public class Baseapplication extends application {public static baseapplication minstance; @Overridepublic void OnCreate ( {super.oncreate (); minstance = this;} public static Baseapplication Getapplication () {return minstance;}}
Because application is a subclass of the context, it is possible to get to application directly
The relationship between application and context