Android task killer

前端 未结 3 1247
心在旅途
心在旅途 2020-12-09 13:46

Im trying to write a simple task killer. I know I shouldnt kill tasks in Android, but Im eager to try something like this. I have the following code:

List<         


        
3条回答
  •  無奈伤痛
    2020-12-09 14:43

    You can't kill other tasks that way because the Kernel will enforce permissions. Try this instead:

    ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
    activityManager.restartPackage(packageName);
    

    you will need the following permissions in the manifest:

    
    
    

    EDIT:

    Actually restartPackage is deprecated. use killBackgroundProcesses() instead!

提交回复
热议问题