I'm working on the project initially created by another developer. There is a root Activity (let's call it CustomActivity
) with code below.
private static SomeOtherClass instance = null;
@Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(null);
if (!(Thread.getDefaultUncaughtExceptionHandler() instanceof CustomExceptionHandler)) {
Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler());
}
// @see http://stackoverflow.com/questions/19545889/app-restarts-rather-than-resumes)
if (!isTaskRoot() && getIntent().hasCategory(Intent.CATEGORY_LAUNCHER) && null != getIntent().getAction()
&& getIntent().getAction().equals(Intent.ACTION_MAIN)) {
finish();
return;
}
instance = new SomeOtherClass();
this.screen = new CustomFragment();
this.getFragmentManager.beginTransaction()
.replace(R.id.content_frame, screen).commit();
...
}
@Override
protected void onDestroy()
{
this.instance = null;
...
}
static public SomeOtherClass getInstance()
{
return instance;
}
this.screen
has a button with CustomActivity.getInstance().methodCall()
on tap. And one of beta testers said he just tapped that button and got crash with this method in stacktrace: Attempt to invoke virtual method '...CustomActivity.getInstance().methodCall()' on a null object reference
.
I don't understand - how it's possible due to Activity lifecycle.
According to stacktrace, onCreate
shouldn't be called after some previous onDestroy
. Even if the last one can happen when we were in another Activity (and yep, this.screen is not nullified anywhere), but this.screen
fragment can't be rendered without Activity recreation. Am I right?
P.S.: there is no more instance
variable management at all and SomeOtherClass
has no custom parent class (just default object).
P.P.S.: nope, device wasn't locked / app just launched. Tester worked with it, rotated phone to remove sim card, removed, rotated back and saw crash alert.
P.P.P.S: don't know why null
in super.onCreate()
but anyhow this Activity has no code to support saved states.