It is crazy that no one has mentioned this elegant solution. This should be the accepted answer.
SplashActivity -> AuthActivity -> DashActivity
if (!sessionManager.isLoggedIn()) {
Intent intent = new Intent(context, AuthActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
context.startActivity(intent);
finish();
} else {
Intent intent = new Intent(context, DashActivity.class);
context.startActivity(intent);
finish();
}
The key here is to use intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
for the intermediary Activity
. Once that middle link is broken, the DashActivity
will the first and last in the stack.
android:noHistory="true"
is a bad solution, as it causes problems when relying on the Activity
as a callback e.g onActivityResult
. This is the recommended solution and should be accepted.