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
If API >= 21, you can use the command of:
finishAndRemoveTask ();
Finishes all activities in this task and removes it from the recent tasks list.
https://developer.android.com/reference/android/app/ActivityManager.AppTask.html
You should use intent flags for that.
What if you have a large stack of activities, will you call from each one to finish them all?
Its much better and easier to just call a Intent.
Hope this helps.
Functionally, there's no difference, but testing this out on GenyMotion there appears to be a slight visual difference. See web cast: https://drive.google.com/file/d/0B8Y77sY7Y2CGRS02c3UyNjd2MGs/view?usp=sharing
You would need to try that on a range of devices to see how consistent it is.
Subjectively, I would say go with the finishAffinity()
because it's more explicit. However, if you have to support < SDK 16 you don't really have a choice.
Try this
Intent.FLAG_ACTIVITY_CLEAR_TOP
it clears the stack of previous activities