Reputation: 445
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());
Upvotes: 0
Views: 116
Reputation: 5068
You cannot kill your application. The Android SDK does not allow this.
Upvotes: 0
Reputation: 2847
Try this. It will kill your application. All your services/receivers, Thread everything would be stopped.
public void onBackPressed() {
System.exit(0);
}
Upvotes: 1
Reputation: 1127
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()
.
Upvotes: 1