Activity A -> Activity B -> Activity C -> Activity D. Pressing back in Activity D should navigate user out of the application, whereas Back should work normally for Activity C, B and A. i.e. C -> back -> B -> back A -> back -> exit.
I tried settings flags with Activity.FLAG_ACITIVITY_CLEAR_TOP, etc.. with different combination. Nothing seems to work. Minimum API level 7.
For
#1 Pressing back in Activity D should navigate user out of the applicationIn ActivityD, you can override onBackPressed or onKeyDown method and then start ActivityA with flag FLAG_ACTIVITY_CLEAR_TOP with an Exit flag(via putExtra method). In ActivityA, you can get that Exit flag value and call finish() if Exit flag is set true.
In Activity A’s onCreate method you will have to do is
In ActivityD’s onBackPressed or onKeyPressed method,
For
#2 Exit from ActivityAYou can simply call finish() method on onBackPressed or onKeyPressed.