I am trying to figure out how I can prevent a user from killing an application using force-stop. I am trying to detect when user opens an activity such as Settings-Applications-Manage Applications and tries to force-stop a protected app. Also there are some task manager apps that allow you to kill processes.
I know it is possible in Android, since apps like AppLock or Super AppLock do it. I just can’t find any information on how to do it.
Right now I am trying to poll ActivityManager.RunningTaskInfo to detect the restricted activities, however that does not work well as they have different names on different devices.
Is there a better way to do it? How do AppLock and similar apps implement this functionality?
I think I figured it out.
Using ActivityManager.getRunningTasks() function seems to be the best solution.
Then you just need to pop-up an Activity (with pin code) every time the top task is “com.android.settings.applications.RunningServiceDetails” or “com.android.settings.applications.InstalledAppDetails”.
Unfortunately, there is no way to see if the user is trying to kill a protected application or some other application, so the access is restricted to all of them.
There are also a bunch of task managers on the market that use ActivityManager.killBackgroundProcesses() method to kill the process, but you can bring the app back to life by using alarms.