简体   繁体   中英

Preventing user from killing an application on Android

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?

Quite similar and relevant question was already asked and replied.

Long story in short, no you cannot prevent user or the operating system to kill your application off due to memory management.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM