安卓:杀死(全部)前台运行的应用程序 [英] Android: Killing (all) Foreground running App

查看:938
本文介绍了安卓:杀死(全部)前台运行的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一种方式来杀死前景的Dalvik应用程序(主动运行)从Linux内核(使用它的进程ID)?

I am looking for a way to kill the foreground Dalvik App(actively running) from the linux kernel(using it's process ID)?

我怎样才能做到这一点?有任何想法吗?请问内核看到正在运行的应用程序的PID?

How can I achieve this? any ideas? Does the kernel see the pid of a running App?

如何为如。进程管理器/任务管理器在Android中实现这一目标?

How does for eg. process Manager/Task manager in Android achieve this?

任何线索?

编辑:

我在看的问题是一路杀一个应用程序,行为不同于预期。

The problem I'm looking at is a way to kill an App that "behaves differently than intended".

这不同的行为始终是固定的。认为它像发送邮件到特定端口。

This "different behaviour" is always fixed. Think of it like sending a message to a particular port.

我怎样才能通过保持它的外面,仍然有权限杀死它杀死一个应用程序?这就是为什么我在想,如果我不得不做出这个框架,如果没有正确的内核这个模块坐。

How can I kill an App by staying outside of it and still having permissions to kill it? That is why I was wondering if I have to make this module sit on the framework if not right in the kernel.

推荐答案

这将得到所有正在运行的进程,并杀死那些与指定的PID:

This will get all running processes and kill those with the specified pid:

ArrayList<Integer> pids = new ArrayList<Integer>();
ActivityManager  manager = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> listOfProcesses = manager.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo process : listOfProcesses)
{
    if (pids.contains(process.pid))
    {
        // Ends the app
        manager.restartPackage(process.processName);
    }
}

您将需要这些权限才能做到这一点:

You will need these permissions to do this:

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

这篇关于安卓:杀死(全部)前台运行的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆