Android kills the application's process when it is in the background and it needs more memory.
I've read a few articles about this. Some people recommend restarting the app when this happens. But none of the articles give me information on how to do something like that.
Is there a way to go back to the root activity after an application's process has been destroyed and the app goes back into the foreground? What would be the best way to do something like this?
The only solution i found that works for me is putting this code in a base class for activities to inherit:
private static boolean isFirstOnCreate = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getLayoutResource());
if (isFirstOnCreate && savedInstanceState != null) {
startActivity(getPackageManager().getLaunchIntentForPackage(getPackageName()));
finishAffinity();
}
isFirstOnCreate = false;