Prevent Activity Stack from being Restored?
If you're working with a spalshScreen or whatever LauncherActivity, you can create a Global static boolean and use it like this :
first find a way to store this static variable (maybe create a Global java file)
public abstract class Global {
...
public static boolean processKilled = true;
...
}
then, in your laucherActivity (MainActivity or Splashscreen ...) add these lines :
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Global.processKilled = false;
...//your code here
}
In fact, if your app process died it surely wont pass through the code of your launcherActivity. So the static boolean processKilled will remain true. Even if it does, that means your app is currently restarting and processkiled will be correclty set to true and all variables correclty instantiated (No NullPointerException)
By creating your own restartApp method you'll get what you want :
(in every activity you have add these lines :)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Global.processKilled){
restartApp();
}
...//your code here
}
EDIT
if you're not a global variable-aholic, you may want to check if savedInstanceState is or isn't null...
The only solution I was able to find was to check a global static variable in every instance of onCreate() and finish if that variable had been reset to null, indicating the task had been restarted. I close all activities down to my root activity and start over.
Soon I hope to have my app at a point where it can save needed values in onPause(), but 'til then this is the only reliable way I know to work with lost initialization...