I am trying to build a task killer type of app in android. I can show the list of currently running task using ActivityManager but facing problem in killing the task.
Here is what i am doing to get the list of currently running task :
ActivityManager am = (ActivityManager) context.
getSystemService(Activity.ACTIVITY_SERVICE);
List<RunningTaskInfo> a = am.getRunningTasks(Integer.MAX_VALUE);
PackageManager pack = this.getPackageManager();
for(int i = 0; i < a.size(); i++) {
String packageName = a.get(i).topActivity.getPackageName();
Drawable d = null;
String appName = "";
try {
d = pack.getApplicationIcon(packageName);
appName = (String)pack.getApplicationLabel(pack.getApplicationInfo(packageName,PackageManager.GET_META_DATA));
} catch (NameNotFoundException e) {
e.printStackTrace();
}
packName.add(packageName); //arraylist of package name
apps.add(appName); // arraylist of app name
icons.add(d); //arraylist of icons
}
It worked for me But now as I am trying to kill the task using killBackgroundProcesses :
am.killBackgroundProcesses(package name);
It did not work . Also killBackgroundProcesses method is available in API level 2.2 then how can i perform the same task in previous API level such as 1.6 etc.
Is there any other way to show the currently active apps and kill them?