The following is based on this post with one added function getAppContext()
:
public class MyApp extends android.app.Application {
private static MyApp instance;
public MyApp() {
instance = this;
}
public static Context getContext() {
return instance;
}
public static Context getAppContext() {
return instance.getApplicationContext();
}
}
But is there any difference between the context returned by getContext()
and getAppContext()
? And is it the same context that is returned by getApplicationContext()
within an Activity
or elsewhere? Are they all what is referred to as the "application context"?