How to finish a series of open routines from one activity?

I am trying to make an exit button for my application. Anyway, I can track the entire instance of activity in my application, and then finish all of them. But in some cases, activity remains. Do not know how. Is there a way to kill a specific application in android. Or in any other way, I can exit my application.

thanks

+1
source share
1 answer

As a rule, you do not need to stop using Android. There a long answer from CommonsWare explains why. However, there are several ways to do this. One such way is the FLAG_ACTIVITY_CLEAR_TOP intent FLAG_ACTIVITY_CLEAR_TOP , which brings the target activity to the top of the stack and closes anything that could have been opened since then. You would use this if you had a button that returns the user from anywhere to the main menu. This button will send the intention to launch the "main menu" with the flag CLEAR_TOP. Then the β€œmain menu” could be closed with a simple finish() , and you would know that none of the other activities were open.

Another way is that if you started other actions using startActivityForResult, you can use finishActivity(requestCode) to close all the actions that were started with this request code.

However, as I wrote above, usually you do not need to do this.

+2
source

Source: https://habr.com/ru/post/900280/


All Articles