Reputation: 2729
I need to find solution, for killing all foreign applications, except a list of allowed applications (this is task for our corporate managers with Android tablets).
Now, I killing foreign applications in this way (code works by timer in service, each 2 sec):
if (killThisProcess) {
Log.i("Process to KILL: ", appProcess.processName);
// kill app
activityManager.killBackgroundProcesses(appProcess.processName);
}
This code works, but only when application in background. User can launch application, do something, and only after application will be in background, it will be killed.
How can I kill process, when it in foreground mode, just after launching?
Thanks.
Upvotes: 3
Views: 877
Reputation: 1808
restartPackage - but now it is deprecated
List<ActivityManager.RunningAppProcessInfo> listOfProcesses = manager.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo process : listOfProcesses)
{
if (pids.contains(process.pid))
{
// Ends the app
manager.restartPackage(process.processName);
}
}
permissions
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.RESTART_PACKAGES"/>
Upvotes: 1
Reputation: 1006604
How can I kill process, when it in foreground mode, just after launching?
Fortunately, you can't, except perhaps on a rooted device when running as superuser.
this is task for our corporate managers with Android tablets
You are welcome to create your own ROM mod that eliminates the apps you do not want and install that ROM mod on the tablets in question.
Or, fire the "corporate managers" who abuse their tablets.
Or, fire the "corporate managers" who do not abuse their tablets, since I can teach a child how to get past your app, and any "corporate manager" stupid enough to not get past your app should not be in a management position.
Upvotes: 4