0

I have an application with 6 activities,

* Home--> A1 ---> A5
* Home--> A2 ---> A5
* Home--> A3 ---> A5
* Home--> A4 ---> A5

And with a menu which can reach directly Home, A1, A2, A3 and A4 from any activities.

I want to add to the menu an item "Exit application".

How can I do this?

Ryan M
  • 269
  • 2
  • 11
Vervatovskis
  • 2,277
  • 5
  • 29
  • 46

6 Answers6

0

Well there is no real "Exit" concept in Android - and your design should not allow users to do so. Take a look at this and see if you can use this thread Is quitting an application frowned upon?

Community
  • 1
  • 1
Vrashabh Irde
  • 14,129
  • 6
  • 51
  • 103
0

You shouldn't do that. Android is designed to manage processes on its own. It will close your application when free memory level becomes low.

User can simply go out of your application by pressing home button.

maciekczwa
  • 46
  • 2
0

Call finish() in every Activity when you move from one Activity to another(before the startActivity() call). That way, there will be no Activity running. And then, whenever you want to exit, simply call finish() on the current Activity too.

Kazekage Gaara
  • 14,972
  • 14
  • 61
  • 108
0

thank you for yours precious answers, i resolve it my self, i think the right way to impose a navigation model is to add global variables of control like:

boolean comeFromA;
boolean comeFromHome;

and case those variables you do the necessary.

Vervatovskis
  • 2,277
  • 5
  • 29
  • 46
0

I had this problem too, and even though it is apparenetly against the whole idea, I just wanted to nuke the app, as it was causing problems of various sorts that I could not figure it out without breaking another part and it did not matter if it started from scratch everytime. (And I did not want to spend any more days hurting my head with it.)

After trying all of the answers from this question and many similar ones I worked out that doing this in each activity solved it.

@Override protected void onPause(){
    super.onPause();
    super.finish();
    int pid = android.os.Process.myPid();
    android.os.Process.killProcess(pid);
}

(For now at least, as I believed I solved it a few times before).

user1529408
  • 219
  • 1
  • 3
  • 10
-1

For "Exit application" you can use -

System.exit();
HTWoks
  • 11
  • 1