public class MyTest {
static MyTest instance = null;
Context appctx = null;
public static MyTest Instance() {
if (null == instance) {
instance = new MyTest();
}
return instance;
}
// call from Application onCreate MyTest.Instance().onAppCreate(this);
public void onAppCreate(Context context) {
appctx = context;
}
// call from Activity onCreate MyTest.Instance().onActivityCreate(this);
public void onActivityCreate(Activity act) {
if (null == appctx) {
Log.d("error", "null app");
}
}
}
Is appctx null because instance is reclaimed by gc or what?
Above is an abbreviated version of a class in my app. appctx would not be null in the onActivityCreate function, but why would appctx be null in some cases
New contributor
Fosky etm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.