Lam Nguyen
Lam Nguyen

Reputation: 51

How to kill android application running in background process

I have an application with call activity, when I finish action in activity the activity is still running in background device. Now I want to stop the activity and not allow it to run in the background when it is finished. I'm also using killBackgroundProcesses but it's not working.

public void KillApplication(String killPackage) {
    ActivityManager am =(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
    android.os.Process.killProcess(runningProcess.pid);
    am.killBackgroundProcesses(killPackage);
}

I just call finish(); and then I use the function KillApplication("mypackage");.

Upvotes: 2

Views: 4551

Answers (2)

RamV13
RamV13

Reputation: 567

From the looks of it, your processes should be terminated. Are you thinking that the process is still running because the application still appears in the 'recents' list? If that's the case, take a look at the "Close application and remove from recent apps" question.

It explains how to remove an application from the recents list by using an Intent flag.

Upvotes: 2

Kharda
Kharda

Reputation: 1368

What do you mean by run in background? The best practice is calling finish(), make sure all the process are stop, and let the OS fully kill the app when it need the resource.

But if you want to force kill, you can use System.exit(1) instead of finish().

Upvotes: 0

Related Questions