CoderDecoder
CoderDecoder

Reputation: 445

How to kill an android application

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

Answers (3)

Waqar Ahmed
Waqar Ahmed

Reputation: 5068

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

Upvotes: 0

MA1
MA1

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

Bharath Mg
Bharath Mg

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

Related Questions