Robin Hood
Robin Hood

Reputation: 1

Clean exiting from an App

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?

Upvotes: 0

Views: 2853

Answers (4)

Barmaley
Barmaley

Reputation: 16363

Clean exit code is:

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

It's a bit odd-looking but workable

Upvotes: 0

Vivek
Vivek

Reputation: 4260

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.

Upvotes: 0

Hussain
Hussain

Reputation: 5562

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..

Upvotes: 1

Ripred
Ripred

Reputation: 157

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

Upvotes: 0

Related Questions