0

I have tried the following code in my back button but it opens the beginning activity again.

    android.os.Process.killProcess(android.os.Process.myPid());
CoderDecoder
  • 445
  • 4
  • 18

3 Answers3

1

As per android guidelines, you should not kill the application. You have to use finish() in each activity lifecycle to safely return to your initial activity and then exit the application.

If you want to exit the app in onBackPressed event on your initial activity, just calling finish() will do the job.

If service, stopSelf().

Bharath Mg
  • 1,117
  • 1
  • 9
  • 18
1

Try this. It will kill your application. All your services/receivers, Thread everything would be stopped.

public void onBackPressed() {
   System.exit(0);
}
MA1
  • 2,767
  • 5
  • 35
  • 51
  • Unless some new version of Android re-launches every application when the process dies. Unfortunately, AshyP have not mentioned the Android version, and whether it is a real device or the emulator. – 18446744073709551615 Jan 30 '14 at 09:30
0

You cannot kill your application. The Android SDK does not allow this.

javathunderman
  • 1,074
  • 2
  • 13
  • 31
Waqar Ahmed
  • 5,005
  • 2
  • 23
  • 45