How do Task Managers kill apps?

后端 未结 4 1566
甜味超标
甜味超标 2020-11-27 20:01

First of all I know it\'s bad to use a task manager/killer in Android and all that, but what I was wondering is how do task managers like Advanced Task Killer k

相关标签:
4条回答
  • 2020-11-27 20:08

    You can send the signal using:

    Process.sendSignal(pid, Process.SIGNAL_KILL);
    

    To completely kill the process, it's recommended to call:

    ActivityManager.killBackgroundProcesses(PackageName)
    

    before sending the signal.

    0 讨论(0)
  • 2020-11-27 20:08

    try this,

    android.os.Process.killProcess(pid)
    

    that will work...

    0 讨论(0)
  • 2020-11-27 20:13

    slayton has good answer in this question.I add this detail to his answer:
    - when you use ActivityManager.killBackgroundProcesses(PackageName) , you can not kill foreground process.

    I saw these open sources project link in K_Anas'answer to this question:
    - github repository
    - code.google

    0 讨论(0)
  • 2020-11-27 20:26

    1- Add to manifest

    <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
    

    2 - In your code

    Runtime.getRuntime().exec("adb shell killall com.example.app");
    

    Note : Your app needs to have access to adb shell system/app (root permission)

    0 讨论(0)
提交回复
热议问题