Code Code - 1 month ago 26
Java Question

How to close other apps

I have simple code for this problem.

ActivityManager activityManager = (ActivityManager) context.getSystemService(- activity -);
activityManager.killBackgroundProcesses(- package name -);


or

ActivityManager activityManager = (ActivityManager) context.getSystemService(- activity -);
activityManager.restartPackage(- package name -);


But i dont know what i can write on activity and package name areas.

Sorry for my English.

Answer

Most likely you can't kill another apps / processes other than your own, simply because how Android OS architecture is set up. Every app lives in it's own sandbox with given resources and access to foreign ones is restricted. Although, I guess if you have rooted smartphone and root privileges, you could achieve your goal in linux kinda way, that is sending kill signal to given PID, try that out.