Imagine that you have 2 activitie - A and B. You're starting B from A. In B you have a task. And if task is completed you want to go back to A when back key pressed if not you want to dismiss the whole application. But after dissmissing you can resume B from recent apps menu. And if after that you need the same behavior of back key.
So I want to dismiss just one activity or the whole app (but with resume possibility). Is there any way to achive that?
In ActivityB
override onBackPressed()
and if the task is completed, just call super.onBackPressed()
which will finish ActivityB
and return to ActivityA
. Otherwise, to dismiss the whole app just use moveTaskToBack()
and don't call super.onBackPressed()
. When the user returns to the app, ActivityB
will be shown (since it has not yet been finished).