5

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?

Alex Gdalevich
  • 685
  • 7
  • 15
  • I thought only system apps were allowed to block that. ie. install with the ROM – Anders Metnik Aug 08 '12 at 14:53
  • AppLock or Super AppLock, does they work on non-rooted devices? Did you try them? Another possible tip is your app is DeviceAdmin. http://developer.android.com/guide/topics/admin/device-admin.html – Maxim Aug 08 '12 at 14:56
  • I've tried Super AppLock on my phone (standard non-rooted) and it works fine. When I try to access Task Manager app or Force-stop the application via Settings/Manage applications I am presented with a screen asking me to enter an unlock code. – Alex Gdalevich Aug 08 '12 at 17:10

2 Answers2

2

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.

Community
  • 1
  • 1
Korhan Ozturk
  • 11,148
  • 6
  • 36
  • 49
1

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.

Alex Gdalevich
  • 685
  • 7
  • 15
  • Does that mean you constantly need to poll using `ActivityManager.getRunningTasks()`? Is that a lot of overhead? I'm also very curious how all these App-locking type apps are doing it, esp. since you can't read other apps' LogCat anymore. – Tony Chan Oct 12 '13 at 02:33