开发者

How to force stop launched process even running on front?

开发者 https://www.devze.com 2023-03-23 18:25 出处:网络
I am writing a task manager service and need to force close any running process, lets say browser, I tried using killBackgroundProcesses,restartPackage,killProcess but none of these force closes proce

I am writing a task manager service and need to force close any running process, lets say browser, I tried using killBackgroundProcesses,restartPackage,killProcess but none of these force closes process ( e.g browser ) when process is on front else they are working.

I want to force stop the process even when process is running on front. What should I开发者_Go百科 do now ??


Solved, here is the code:

Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
Appmgr.killBackgroundProcesses(RunningP.processName);


I had this problem like you.I used a method in the service that killed the background process.So whenever i need to kill process that is running in the foreground i just brought my Activity in the foreground.So the process want to kill automatically goes background and can be killed with killBackgroundProcess.

But surely this is not really a good practice

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号