我正在尝试使用我的应用程序终止后台运行的应用程序,但我无法终止该进程。
android.os.Process.killProcess(pid);
android.os.Process.sendSignal(pid,
android.os.Process.SIGNAL_KILL);
manager.killBackgroundProcesses(pid);
这里 pid 是后台运行的进程 ID。
我正在尝试使用我的应用程序终止后台运行的应用程序,但我无法终止该进程。
android.os.Process.killProcess(pid);
android.os.Process.sendSignal(pid,
android.os.Process.SIGNAL_KILL);
manager.killBackgroundProcesses(pid);
这里 pid 是后台运行的进程 ID。
每个 Android 应用程序都有自己的用户 ID、组 ID,并且大部分时间都在自己的进程中运行。所以你的应用程序可能没有权限杀死其他进程。
显然存在设计缺陷,您最好说明您实际上想要做什么。
使用这个 killBackgroundProcesses:
try {
ActivityManager actvityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
actvityManager.killBackgroundProcesses(pkgn.toString());// pkgn is a process id /////
} catch (Exception e) {
e.printStackTrace();
}
您还必须在清单中添加它
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />