0

I want to kill other application, I have googled and see other answer on stackoverflow but didn't get satisfied answer. Here I am trying to kill browse app (for testing). What I want to do is, I want to kill application using package name.

    Log.d("Process", "in intent");
    ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> pids = am.getRunningAppProcesses();
    int processid = 0;
    Log.d("Process",String.valueOf(pids.size()) );
    for(int i = 0; i < pids.size(); i++)
    {
        //Toast.makeText(getApplicationContext(),"on if", Toast.LENGTH_SHORT).show();
        ActivityManager.RunningAppProcessInfo info = pids.get(i);
        if(info.processName.equalsIgnoreCase("com.android.browser")){
            Log.d("Process", "in if");
            //Toast.makeText(getApplicationContext(),"in if", Toast.LENGTH_SHORT).show();
           processid = info.pid;
           Log.d("Process",String.valueOf(processid) );
           android.os.Process.sendSignal(pids.get(i).pid, android.os.Process.SIGNAL_KILL);
           android.os.Process.killProcess(processid);

        } 
    }

this is my code can someone help me out? what i am missing?

in logcat I am getting sending signal. PID :1524 SIG: 9

Konrad Krakowiak
  • 12,285
  • 11
  • 58
  • 45
Mrugank Dhimmar
  • 202
  • 3
  • 14
  • You "didn't get satisfied" because **you are not supposed to do that**, something the other answers no doubt made rather clear. – Chris Stratton May 15 '15 at 19:07

1 Answers1

2

READ FIRST, IMPORTANT: You can only kill a process that has the same userID as the one that is doing the killing. If you are trying to kill your own process it should work. Otherwise you can't do it (unless you have a rooted device and your application has root priviledges).


You'd need to use ActivityManager: see http://developer.android.com/reference/android/app/ActivityManager.RunningAppProcessInfo.html for the process info.

You could:

  1. Get all running app processes.
  2. Find your app.
  3. Get its PID.

When you get the PID:

android.os.Process.killProcess(PID);
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109