1

如何知道其他应用程序正在我的应用程序的设备中运行,以便使用我的应用程序我可以杀死其他正在运行的应用程序。在安卓中可以吗?

提前致谢

4

3 回答 3

2

你可以这样看到它们:

activityManager = (ActivityManager) this
                    .getSystemService(ACTIVITY_SERVICE);
            arylistTask = new ArrayList<String>();
            List<ActivityManager.RunningTaskInfo> mRunningTasks =
            activityManager.getRunningTasks(30);

但我不太确定你能不能杀了他们。我徘徊作为你的答案@Aki,一些任务管理应用程序是如何工作的?只是为了好奇。

于 2012-04-05T11:30:20.587 回答
1
// Get currently running application processes
    List<ActivityManager.RunningAppProcessInfo> list = servMng.getRunningAppProcesses();
    if(list != null){
     for(int i=0;i<list.size();++i){
      if("com.android.email".matches(list.get(i).processName)){
       int pid = android.os.Process.getUidForName("com.android.email");
             android.os.Process.killProcess(pid);
      }else{
       mTextVIew.append(list.get(i).processName + "\n");
      }
     }
    }

---------------------------------------------------------------------------

    // Get currently running service
    List<ActivityManager.RunningServiceInfo> list = servMng.getRunningServices(1024);
    if(list != null){
     for(int i=0;i<list.size();++i){
      mTextVIew.append(list.get(i).service.getClassName() + "\n");
     }
    }


---------------------------------------------------------------------------

    // Get currently running tasks
    List<ActivityManager.RunningTaskInfo> list = servMng.getRunningTasks(1024);
    if(list != null){
     for(int i=0;i<list.size();++i){
      mTextVIew.append(list.get(i).toString() + "\n");
     }
    }


---------------------------------------------------------------------------

This example captures the Android Native "back" button event from the hardware back button and prompts the user "do you really want to leave my app" and if the user selects "yes" it kills the App.

 @Override 
public boolean onKeyDown(int keyCode, KeyEvent event) {
    //Handle the back button
    if(keyCode == KeyEvent.KEYCODE_BACK) {
        //Ask the user if they want to quit
        new AlertDialog.Builder(this)
        .setIcon(android.R.drawable.exclamationpoint)
        .setTitle("Exit?")
        .setMessage("You are about to exit the Application. " + 
                     "Do you really want to exit?")
        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
             @Override
            public void onClick(DialogInterface dialog, int which) {
                //Stop the activity
                 //maintenancetabs.this.finish();
                 int pid = android.os.Process.myPid();
                 android.os.Process.killProcess(pid);
                }
         })
        .setNegativeButton("No", null)
        .show();
         return true;
    }     else {
        return super.onKeyDown(keyCode, event);
    }
 }
于 2012-04-05T11:33:53.907 回答
0

绝对不可能从您的应用程序中杀死其他正在运行的应用程序。那将是一个巨大的安全问题。

于 2012-04-05T11:27:48.373 回答