Im working on a simple task manager that would allow user to kill running processes and terminate applications. Im getting a running processes list using:
List<RunningAppProcessInfo> procInfo = activityManager.getRunningAppProcesses();
With one click of a button I want to kill all running processes that arent important or essencial in any way. For this, Im using:
ArrayList<String> packages = new ArrayList<String>();
for (int i = 0; i < procInfo.size(); i++) {
String process = procInfo.get(i).processName;
if (!packages.contains(process)) {
packages.add(process);
}
}
This will get me names of all running processes and now I should probably filter them somehow using their importance code:
int importance = procInfo.get(i).importance
But Im not really sure how. What should I keep running and what is safe to kill? Im using
applicationManager.killBackgroundProcesses(process);
to kill my process. My next question is, is this the best way to kill a process? Because when I do it like this and than I open again one of the applications for which all processes were killed, I find myself not in its Main Activity but right there where I left it, so I asume that the application was never terminated even though all its processes were killed. Also, I fint that application in quite a desolate state (ImageViews and Buttons are missing, TextViews arent where theyre supposed to be). Note that this application is also written by myself and normally it works perfectly fine.
My last question is, when this problem with killing processes is solved, I want also to terminate selected applications. How do I get the list of running applications? I was thinking getting a list of running processes and than somehow get applications from that list. After that, terminating a selected application by killing all its processes. But I dont think thats the best way since it obviously didnt work when I killed all processes.
Thank you for any reply!