Is it possible to stop the service using android: persistent = "true"

I am looking to create a system service while using system permissions. The service must be limited to activities and meet the following requirements.

  • The service will not be killed by the system.
  • The service can be stopped upon request.

To achieve the first requirement, I created my service using Context.bindService () by creating an associated system service and adding android: persistent = "true" to the service manifest informing the system that this service should be running all the time.

Unfortunately, after adding android: persistent = "true" I cannot stop the service either via Context.unbindService () or by calling Context.stopService ()

Is it possible to stop the service using android: persistent = "true" and if not, what should be my approach to achieve both requirements.

+3


source to share


1 answer


I just went through something similar. As per this answer, you need to call stopService()

and then unBindService()

call both in that order. Place them in a host method onDestroy

. Also, just in case your service wakes up periodically by AlarmManager like mine, remember to call it as well cancel()

.

As you probably know, you can check the startup of services in ApplicationManager. When checking these changes, force stop any services that you might have started with the old code.



As for the flag persistent

, I think, according to this , that it is only valid for system application developers. In a typical application in the marketplace, I think the flag is being ignored.

0


source







All Articles