Home » Android » Killing android application on pause

Killing android application on pause

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have an application which I would like to be fully disabled/closed when it is paused (IE. When the user presses the Home, End (call) and Back button I would like the application to be closed, instead of being saved in the history stack).

How do I do this….?

Thanks.

How to&Answers:

Implement onPause() in your activity and call finish() on your activity. Bear in mind, though, that this will occur on every pause, including dialogs, incoming calls, users activating a Notification. You might want to consider doing finish() in onStop(), which would at least solve the dialog problem.

Also, bear in mind that users will may get confused when using your app, thinking it has crashed since it is gone when they try to get back to it.

Answer:

you can easily do that by setting true the “noHistory” attribute in to your activity element, in the manifest

http://developer.android.com/guide/topics/manifest/activity-element.html#nohist

Answer:

You know how you have an OnCreate() method in your activity which performs actions when you start. You need to add something like:

@Override

protected void onPause(){
finish();

        super.onPause();

}

in your activity to add actions before it starts

in this case the

finish(); 

command is what you want to execute before your activity pauses.