Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop application from running in background?

Tags:

android

How to stop application from running in background in android? I want my application to start fresh everytime it loads. How to do it programatically.

like image 678
James Avatar asked Jan 20 '12 11:01

James


People also ask

How do I permanently stop apps running in the background Android?

Here's how: Go to Settings > General > Background App Refresh. From the list of apps shown, use the toggle to turn Background App Refresh on or off for each app.


1 Answers

Override onStop method of your activity:

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

But I think it's a bad idea to restart your app each time. It's better to override onStart method, and handle "restart" here.

Actually, your app doesn't "run" in background. Android OS keeps it in memory, or saves state of your activity to device (and then you can load it, using savedInstanceState param in onCreate method).

like image 114
Dmitry Zaytsev Avatar answered Sep 20 '22 03:09

Dmitry Zaytsev