I need to have have reference to Context in my utils class.
First I am extending Application class and initializing my util class:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Utils.init(getApplicationContext());
}
}
And utils class looks like:
public class Utils{
private static Context sContext;
private Utils() {
}
public static void init(Context context) {
sContext = context;
}
}
Is there any possible way to get a leak with such approach?
I can see only one case: when application goes background - Context can be re-created, and so Utils class may be re-initialized even if it will persist in memory.
Any suggestions, please.