1

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

Shahtaj
  • 51
  • 1
  • 2
  • 4

3 Answers3

1

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.

Mojo Risin
  • 8,136
  • 5
  • 45
  • 58
0

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());
sachit
  • 1,128
  • 2
  • 12
  • 25
0

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?

Community
  • 1
  • 1
Jaydeep Khamar
  • 5,975
  • 3
  • 32
  • 30