2

I made three .xml files before the activity_main.xml and set a timer of 5 sec one by one for each xml file by using thread.So it takes 15 sec to reach to the main activity.

I have a problem in my EXIT button I use

system.exit(0);          //behaving similar as finish()

but it returns me to the previous xml file not from the entire app. I want to exit from entire app in a single click.

pa1pal
  • 743
  • 3
  • 14
  • 32
  • 1
    do not use `System.exit(0)`. Use Navigation Drawer for navigation. – Raghunandan Nov 04 '13 at 17:29
  • 1
    You don't need navigation drawer for navigation. In general, Android apps don't "exit". If the user wants to use another application, he will just go to the HOME screen (putting your application in the background) and start another app. At some point Android will just kill your application because it has been unused for some period of time. You don't need to provide the user a way to "exit". – David Wasser Nov 04 '13 at 17:38
  • http://stackoverflow.com/questions/6330200/how-to-quit-android-application-programmatically – GoodSp33d Nov 04 '13 at 17:41
  • Do you have 4 different activities? – Mads Frandsen Nov 04 '13 at 17:44
  • 1
    If you suppose a tree structure for your application, the first screen of your application will be the root of the tree and the screens that will open from your apps home screen, will be the child nodes or leaves of the tree. So if you need to implement a mechanism for exiting an app, make sure that, when you travel from child node or leaf activity to root activity, you exit from that activity, instead of just calling Intent to launch the activity. – Chintan Soni Nov 04 '13 at 17:49
  • @Madsfrandsen 4 xml files in one app for icon , menu , about and home screen when i click exit it took me to the previous screen. – pa1pal Nov 04 '13 at 17:50
  • 1
    suppose you have activity path a->b->c. When you are travelling from root to leaf (a->b->c) you may or may not call finish, simply call the Intent for launching new activity. But when you travel from c->b you should call `finish()` and then call the Intent. Same is the case for b->a. In this way, you will be removing previous activities from the stack, from the home screen when you implement for "back" button, you just need to call finish() and your app will be exited. – Chintan Soni Nov 04 '13 at 17:58

2 Answers2

2

In your Manifest.xml, you should add android:noHistory="true" in your <activity> tags. Additionally, you should not call system.exit(0), but instead just use finish().

By doing this, the activities will not be added to the back stack, and therefore, pressing the exit button (or the back button) will let the user exit the app.

Mads Frandsen
  • 523
  • 4
  • 12
-1

Try Like this

moveTaskToBack(true);

For reference moveTaskToBack

Amit Gupta
  • 8,914
  • 1
  • 25
  • 33