Reputation: 51
Hi I am trying to close the android application from the program ie. I have an exit option in my application which will close the running android application.
If there is a single activity pushed inside the stack, we can use finish() to close the application and activity as well.
If there are number of activities inside the stack how can we quit the application ?
If anybody know solution/api for closing whole application, please do reply to this post.
Thanks
Upvotes: 1
Views: 1662
Reputation: 1138
for closing application you can use either of these methods.
moveTaskToBack(false);
or
System.runFinalizersOnExit(true);
or
android.os.Process.killProcess(android.os.Process.myPid());
Upvotes: 0
Reputation: 5985
Use this code:
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
also May be this can be helpful in getting your answer How to close Android application?
Upvotes: 0
Reputation: 8142
You can use Service and bind all your activities to the service. When you want to quit your application just call finish to all binded Activities. MusicUtils from android's default music player can give you a clue how to implement this.
Upvotes: 1