ActivityManager am = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
final PackageManager pm = getPackageManager();
// get a list of installed apps.
List<ApplicationInfo> packages = pm
.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
if (pm.getLaunchIntentForPackage(packageInfo.packageName) != null) {
am.killBackgroundProcesses(packageInfo.packageName.toString());
}
}
---------------------------------------------------------------------------------
0 2 | Im trying to write a simple task killer. I know I shouldnt kill tasks in Android, but Im eager to try something like this. I have the following code:
My problem here is that when I perform this code, I first get the list of all tasks, thats ok. Than I see in the log several lines of:
I asume thats a signal to die. But at the end of my code, when I display all running processes, the list is the same as before, no task has been killed. Any ide why? Thank you!
| ||
feedback |
0 | You can't kill other tasks that way because the Kernel will enforce permissions. Try this instead:
you will need the following permissions in the manifest:
EDIT: Actually restartPackage is deprecated. use killBackgroundProcesses() instead! | ||
feedback |
1 | To achieve best result form killProcess , try calling killProcess many times.as
NOTE: version 2.2 - killBackgroundProcesses : " This is the same as the kernel killing those processes to reclaim memory; the system will take care of restarting these processes in the future as needed."
Required Permissions:
version 2.1 - restartPackage -" This method is deprecated. (works for version less than 2.2. This is now just a wrapper for killBackgroundProcesses(String); the previous behavior here is no longer available to applications because it allows them to break other applications by removing their alarms, stopping their services, etc."
Required Permissions:
| ||
feedback |
0 | Fortunately, killProcess() will only work for you to kill your own processes. You can tell this byreading the documentation. | ||
Was this post useful to you? |