tags:

views:

58

answers:

1

Hi, I am trying to make an exit button for my application. Anyhow I am able to track all the instance of activity in my application and then finish them all. But still some activity remain alive in some cases. Dont know how. Is there any method to kill a particular application in android. Or any other way can I exit from my application.

Thanks

A: 

Generally one doesn't need to quit applicatios in Android. There's a long answer from CommonsWare here explaining why. However, there are a few ways it can be done. One such way is the intent flag FLAG_ACTIVITY_CLEAR_TOP which brings the targeted activity to the top of the stack and closes anything else that may have been open since. You'd use this if you had a button that brought the user back from wherever they were to the 'main menu' activity. That button would send an intent to start the 'main menu' with the CLEAR_TOP flag. The 'main menu' could then close with a simple finish(), and you'd know that none of the other activities were still open.

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

However, as I wrote above, generally you shouldn't need to do this.

Steve H