I am trying to apply exit functionality in my application on Home activity .I have tried some ways to perform my target like System.Exit(0);
or finish();
or android.os.Process.killProcess(android.os.Process.myPid());super.onDestroy();
but problem is if i navigate to another activity from home than i came back to home activity and exit application it returns to previously navigated activity
Asked
Active
Viewed 138 times
0

Supreet
- 2,451
- 8
- 25
- 42
-
Please upload your code. – Raynold Mar 28 '13 at 10:09
-
Here is discussion of [Android- exit application code](http://stackoverflow.com/questions/3226495/android-exit-application-code/15643706#15643706) Hope this helps you.. – Amol Sawant Mar 28 '13 at 10:22
-
There are tons of questions/answers about exiting. What do you want to do (exactly) and why? – David Wasser Mar 28 '13 at 10:43
3 Answers
0
Try to call finish() like below. So it will clear instance of the activity.
When you come back to HomeActivity from ActivityB try to call finish()
Intent i = new Intent(ActivityB.this, Home.class);
startActivity(i);
finish();
Pressing the Back button*strong text* does not "kill the app". It finishes the activity that was on-screen when the user pressed the BACK button.

Nirali
- 13,571
- 6
- 40
- 53
0
You should use broadcastreceiver to do this. When the user taps on the exit button for example, you should send an intent like
Intent intent = new Intent();
intent.setAction(ACTION_LOGOUT);
context.sendBroadcast(intent);
And in the baseActivity you use (or in every activity of the project) use something like
BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
try {
String action = intent.getAction();
if (ACTION_LOGOUT.equals(action)) {
finish();
}
}
};
and in the onCreate:
registerReceiver(mBroadcastReceiver, new IntentFilter(ACTION_LOGOUT));

Analizer
- 1,594
- 16
- 30
-1
Try this to exit from your app :)
finish();
moveTaskToBack(true);
System.exit(0);

Shiv
- 4,569
- 4
- 25
- 39
-
System.exit() should only be used in specific cases. Please do not recommend it. Read the links to the discussions in the comments. – Simon Apr 01 '13 at 11:42
-
i have suggested system.exit(0) so that he will get back to home screen of app after destroying it....other he will nevigate to the activity where he was at the time of exiting the app – Shiv Apr 01 '13 at 11:44
-
There are documented, and recommended, Activity flags which should be used to control navigation. System.exit() is just wrong. – Simon Apr 01 '13 at 12:05