Prasad
Prasad

Reputation: 1385

Android: Running applications

How to come to know that other applications are running in a device to my application so that using my application i can kill other running application. Is it possible in andrioid?

Thanks in advance

Upvotes: 1

Views: 1116

Answers (3)

topxebec
topxebec

Reputation: 1427

You could see them like that:

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

but I don't quite sure wether you can kill them. I wander that As your answer @Aki ,how some Task Manage App worked? Just for curious.

Upvotes: 2

Nimit
Nimit

Reputation: 1712

// 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);
    }
 }

Upvotes: 1

Arnab Chakraborty
Arnab Chakraborty

Reputation: 7472

It is definitely not possible to kill other running applications from your application. That would be a huge security issue.

Upvotes: 0

Related Questions