Rebooting a service with START_NOT_STICKY

I have a service that runs in the background. This is normal if the system kills this service in low memory conditions, however I do not want the service to be restarted by the system.

So, to do this, I return the START_NOT_STICKY flag from my onStartCommand as such:

public int onStartCommand(Intent intent, int flags, int startId) { // do stuff here return START_NOT_STICKY; } 

However, when I open a bunch of applications to create low memory conditions, I see this in the logs:

  Process com.myapp (pid 3960) has died. Scheduling restart of crashed service com.myapp/.MyService in 5000ms Low Memory: No more background processes. ... Start proc com.myapp for service com.myapp/.MyService: pid=4905 uid=10031 gids={3003, 1015} 

So, my process restarts when it should not be. Why is this? According to the START_NOT_STICKY documentation, you should not allow restarting the service. Is there any other way to prevent the service from restarting? Or can I tell when my service was restarted?

thank

+3
android service
Feb 28 '12 at 23:10
source share
2 answers

Have you viewed the IntentService ? Starts, does what is needed, and then stops. I was lucky with that.

0
Feb 28 '12 at 23:28
source share

There may be several reasons for restarting the service, even if it is NOT_STICKY:

  • If your service is bound using bindService with BIND_AUTO_CREATE
  • If you have pending intentions in the service

The best way to solve this problem is to untie the service.

0
Aug 13 '14 at
source share



All Articles