Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent some users from closing Android service

I'm making a service on Android where it will be installed on a phone/tablet. Many people can use that tablet but only selected ones should have right to close the service. How can I achieve this? I googled & found some options:

  • Making user accounts: There are lots of apps for this but they do not specify whether service running in one account will run for other accounts also.
  • Prompt for password before closing service : There are Many stackoverflow Q.for this but looks impossible.
  • Restart service when user closes it : Restarting may lead to loss of data as my service is continuously communicating with other devices to collect data.

NEW OPTION:

I have another idea to make it work : I'm will make it system app so that it will warn user when he tries to stop it. For system apps, when user presses the "stop" button from settings, a warning message pops up :" Closing this app may lead to..(blah blah)....". Do you know which intent is thrown to pop up this message? I think I can use that intent here and disable the "OK" option in this message

I want to disable this "OK".

like image 493
Nikhil Chilwant Avatar asked Jun 10 '14 15:06

Nikhil Chilwant


1 Answers

Even if the user couldn't stop the service, the phone could still get powered off, run out of battery, or lose network connectivity. It's even conceivable that Android could kill the service process if it ran low on resources. So the code should be prepared to for handling the potential data loss in those events.

I'm not certain how you detect when the service has been stopped, but there's always AlarmManager for periodic polling.

like image 131
selbie Avatar answered Sep 18 '22 17:09

selbie