I use this code to restart my app.
Intent i=getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
It does restart the app, jumps to first launch activity. But it goes back to the fragment where the intent was executed when I press back.
Then I added this to nullify backstack:
fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
Then now when I press back button it goes back to the activity holding the fragment from earlier.
Question:
Should I just override onBackPressed
on the first launch activity or is there a better way?
Screen A - Splash
Screen B - First Launched Screen
Screen C - Main
Here is what happens when I restart (from main) without finish: C -> B -> A -> *back pressed -> C
So I added finish, then here is what happens: C -> B -> *closes, not a crash
But I already found the answer.