0

I want to put a menu button 'Exit' in order to let user to leave the App. I read that I could use moveTaskToBack. This works but I would like the user to re-enter in the App through Home Activity and not the Activity he left.

Do you have any suggestion?

Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168
Robin Hood
  • 1
  • 1
  • 1
  • It is really not recommended under the Android guidelines to have an exit button. Recfactor your activity stack to allow easy exits through finish(); – MrZander May 20 '13 at 22:26

4 Answers4

1

public void terminate() { Log.i("myid","terminated!!"); super.onDestroy(); this.finish(); }

and have a look at this fine answer.
and also have a look at here..

Community
  • 1
  • 1
Hussain
  • 5,552
  • 4
  • 40
  • 50
  • I only want to let my users to leave the app. moveTaskToBack is good for me, but I would like if the user could re enter always on Home Activity. Becasue I think is useful a button that 'reset' everythink. I know user could press Home more times until he go on Home Screen but I want a more quick way. – Robin Hood Apr 07 '11 at 07:35
0

For my android apps on my exit button I use a call to finish(); Maybe this is what you are looking for?

Ripred
  • 157
  • 8
  • finish() let me left last Activity and switch to previous one only.I want that user can left app at all – Robin Hood Apr 07 '11 at 07:14
  • @Robin - Maybe you need to add code to your onResume() method to force the state and current Activity you want the user to default to each time the app is run/resumed? IIRC Android really doesn't support 'quitting' the app unlike iOS. The links @Hussain provided are also very useful. – Ripred Apr 07 '11 at 07:26
0

Well robin hood,

my understanding to your code is that, when user press Exit button it should leave app and when you restart app it should resume from previous activity where application left.

Actually it is same behavior when we press Home button. So you just need to create event home button pressed on exit click.

=======================================

Ok, I don't know following solution is good but. If you want to terminate entire app and resume from home activity. You can put launchMode to sigleinstance in menifeast file for other activities.

or

You can set a static flag when exit button pressed recursively exit the activities.

Vivek
  • 4,170
  • 6
  • 36
  • 50
0

Clean exit code is:

System.gc();
android.os.Process.killProcess(android.os.Process.myPid());

It's a bit odd-looking but workable

Barmaley
  • 16,638
  • 18
  • 73
  • 146
  • I haven't "religious" problem on that, but It doesn't function. only close the current activity :-) – Robin Hood Apr 07 '11 at 10:32
  • Am also facing the same issue. for one activity it works fine but for one of my other activity it doesn't work. – Sathesh Nov 07 '13 at 03:55