Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Static Application Context Method
In Android Manifest file declare following
<application android:name="com.xyz.MyApplication">
</application>
then write the class
public class MyApplication extends Application{
private static Context context;
public void onCreate(){
super.onCreate();
MyApplication.context = getApplicationContext();
}
public static Context getAppContext() {
return MyApplication.context;
}
}
Now every where call MyApplication.getAppContext() to get your application context statically.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment