Create a new Java Inheritance application class
Importandroid.app.Application;ImportAndroid.content.Context;/*** Write custom application to manage global status information, such as context *@authorAutumn*/ Public classMyApplicationextendsApplication {Private Staticcontext Context; @Override Public voidonCreate () {Super. OnCreate (); //Get ContextContext =Getapplicationcontext (); } //return Public StaticContext Getcontextobject () {returncontext; }}
Register in Androidmanifest.xml and add Android:name= "com.*** to the application tag. MyApplication "Can
<ApplicationAndroid:name= "com.***." MyApplication "Android:allowbackup= "true"Android:icon= "@mipmap/ic_launcher"Android:label= "@string/app_name"Android:roundicon= "@mipmap/ic_launcher_round"Android:supportsrtl= "true"Android:theme= "@style/apptheme"></Application>
Call Get Global Context
Myapplication.getcontextobject ();
Android Settings Global Context