In Android, if you want to clear your current Activity
stack and launch a new Activity
(for example, logging out of the app and launching a log in Activity
), there appears to be two approaches.
Are there any advantages to one over the other if your target API level is above 16?
1) Finish Affinity
Calling finishAffinity()
from an Activity.
Activity.finishAffinity
2) Intent Flags
Intent intent = new Intent(this, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
The finishAffinity()
approach is suitable for >= API 16.
The Intent
flags approach is suitable for >= API 11.
To be clear, for the purpose of clearing the current Activity
stack, both approaches appear to work equally as well. My question is are there are problems with either that people have experienced and, therefore, is there any reason to choose one over the other?