In my app there's a static variable that's being set to null when I return to my app from the external browser. Seems like the app or some portion of it is killed if the external web page I'm launching is complex enough.
If the app were to be killed entirely and then relauched from the main activity that would be ok, but the relaunch is from the activity that started the browser - and it's not meant to set the app state so it's crashing when accessing the null static variable. This is a one-out-of-six device problem for me so I need some advice.
Is there a flag to set to prevent this behavior?
You probably just want to follow the second link by kabuko. But if you want to keep your static variable (perhaps you have some great reason for this), you could do this:
That way you can replace your calls to myVar.test() with getVariable().test() and you know it will never cause a null pointer exception.
Whenever you left your app & switching browser your app got in background. So you need to follow these steps
First initialize your static variable in Sharedpreferece or in savedInstanceState as follow
or
in the first execution of
oncreate()
method of activity or elsewhereonResume()
methods via sharedpreference or savedInstance whichever is used earlier.