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).
To dismiss an Activity, you can call its finish() method. And for dismissing the whole application, try launching an Intent for the Home Activity. Take a look to this: How to Launch Home Screen Programmatically in Android
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.