How do Task Managers kill apps?
Asked Answered
P

4

16

First of all I know it's bad to use a task manager/killer in Android and all that, but what I was wondering is how do task managers like Advanced Task Killer kill other applications?
I wanted to develop a simple application that would do this, just for the learning experience.
I tried executing the Linux command kill pid from my application but it didn't work, maybe it requires root?

So, how do I accomplish this from my application? I have a simple ListActivity that shows the currently running tasks and when a user long-presses an item I want to kill that task.

Prindle answered 10/6, 2011 at 8:3 Comment(2)
have a look at https://mcmap.net/q/357516/-android-task-kill, which covers this.Henrieta
Thanks, but I've already read that post :) It doesn't answer my question though, the Process.killProcess function only allows one to kill my own process and not others, if I'm not wrong. I also tried it on my application but it didn't work :/Prindle
P
12

You can send the signal using:

Process.sendSignal(pid, Process.SIGNAL_KILL);

To completely kill the process, it's recommended to call:

ActivityManager.killBackgroundProcesses(PackageName)

before sending the signal.

Prindle answered 12/6, 2011 at 19:23 Comment(3)
where is ActivityManager.killBackgroundProcesses... it says that the method is undefined...Vite
so does this really kill external applications? I'm not quit sure how to check this. ActivityManager.killBackgroundProcesses(PackageName); Process.sendSignal(pid, Process.SIGNAL_KILL);Limousine
does it? I have the same problemTombola
V
1

slayton has good answer in this question.I add this detail to his answer:
- when you use ActivityManager.killBackgroundProcesses(PackageName) , you can not kill foreground process.

I saw these open sources project link in K_Anas'answer to this question:
- github repository
- code.google

Velamen answered 25/7, 2012 at 12:15 Comment(0)
P
0

try this,

android.os.Process.killProcess(pid)

that will work...

Patricapatrice answered 25/7, 2012 at 9:32 Comment(0)
L
-2

1- Add to manifest

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

2 - In your code

Runtime.getRuntime().exec("adb shell killall com.example.app");

Note : Your app needs to have access to adb shell system/app (root permission)

Lasso answered 26/10, 2016 at 15:29 Comment(1)
You need to have root permission for thisEunuchoidism

© 2022 - 2024 — McMap. All rights reserved.