In my Application subclass, I save a static reference to Context, so that I don't have to pass contexts around in the rest of my code. I just use MyApplication.getAppContext() whenever I need the application Context:
public class MyApplication extends Application {
private static Context context;
public void onCreate() {
super.onCreate();
context = getApplicationContext();
}
public static Context getAppContext() {
return context;
}
}
Is this safe? Is there a possible scenario where MyApplication.getAppContext() returns null?