John Watson
John Watson

Reputation: 869

How to close application totally

Application is having 2 activities. I am using following code in each activity to close the application totally and free all resources when home button is pressed. But when i restart the app, it starts from the activity it left earlier. How to achieve the objective.

@Override
public void onStop(){
    super.onStop();
    super.onDestroy();
}

Upvotes: 0

Views: 692

Answers (4)

AAnkit
AAnkit

Reputation: 27539

Call finish() instead of this and you must exit the app from the main activity itself.
If you pressing Home button on any activity , it will start the same Activity next time.

Or add more detail in your question for better solution.

Upvotes: 0

Jin35
Jin35

Reputation: 8612

  1. Do not close application totally. Let system itself decide.
  2. Do not call super.onDestroy() in onStop method!
  3. Use finish() for activity stoping.
  4. You always have System.exit()

Upvotes: 1

Sumant
Sumant

Reputation: 2795

Finish all the activity first and before finishing last activity just add the below line

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

which will kill the process which is started for that application.

Upvotes: 0

Kazekage Gaara
Kazekage Gaara

Reputation: 15052

You cannot close your application at your need. You can call finish() in every Activity when you navigate away from it. But then again, there is no guarantee that the OS will free up the resources immediately and close your Activity.

Never try to implement something like exiting your application. Read this for a good discussion on it.

Upvotes: 1

Related Questions