繁体   English   中英

在Android中杀死在后台运行的应用程序

[英]Kill the applications running in background in android

我正在尝试使用我的应用程序终止后台运行的应用程序,但无法终止该进程。

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" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM