2

我尝试使用以下代码杀死正在运行的应用程序,但它不起作用,请提供任何建议。使用restartPackage(), KillingBackgroundProcess()android.os.processes.killprocess(pid)但没有任何效果。android 或 android 内核是否不支持它没有给我们太多权限来杀死其他应用程序。

Intent ints = new Intent(Intent.ACTION_MAIN, null);
ints.addCategory(Intent.CATEGORY_LAUNCHER);

checkedapp = name.get(position);

Log.w("Checked app name", checkedapp);

PackageManager pm = getApplicationContext().getPackageManager();

List<ResolveInfo> intentlist = pm.queryIntentActivities(ints,
                        PackageManager.PERMISSION_GRANTED);

ActivityManager am1 = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

List<RunningTaskInfo> processes = am1.getRunningTasks(Integer.MAX_VALUE);

if (processes != null) 
{
  for (int i = 0; i < processes.size(); i++) 
  {
    String packageName = processes.get(i).topActivity.getPackageName();

    Log.w("packagename", packageName);
    RunningTaskInfo temp = processes.get(i);

    try 
    {
      pName = (String) pm.getApplicationLabel(pm.getApplicationInfo(packageName,
                                        PackageManager.GET_META_DATA));
    } 
     catch (NameNotFoundException e) 
    {
      // TODO Auto-generated catch block
       e.printStackTrace();
    }

    if (checkedapp.equals(pName)) 
    {

      am1.killBackgroundProcesses(packageName);

      //String pid = Integer.toString(temp.id);

        int pid=temp.id;

    android.os.Process.killProcess(pid);    

//Log.w("processid", pid);

icons.remove(position);
name.remove(position);

} 

Is it really not possible to force stop any running application in android programmatically.
Please help.
4

1 回答 1

2

这不可能从你的进程中杀死另一个应用程序的进程,从 ICS 来看,这个限制意味着。您编写的代码可能适用于早期版本,但我从未尝试过它们。

于 2013-07-11T09:00:33.597 回答