21

I am creating a service for my android app, providing data to the service via Intents. The problem is that when the service is destroyed by the system than the intent data provided to it can't be restored, as a result of which my app crashes.

I have heard START_REDELIVER_INTENT will restart my service as soon as there is sufficient memory available restoring the intent data provided to service whereas the START_STICKY will not restore the intent data.

am i right ? or is there something I don't know ?

Also my service is taking forever to restart after it is destroyed by the system.

enter image description here

Rakesh
  • 1,133
  • 4
  • 13
  • 28

2 Answers2

30

START_STICKY- It will tell the system to create a newest copy of the service, when available memory is sufficient to do, after it retains state and recovers from the low memory. In this process we will loose the results that might have calculated before.

START_REDELIVER_INTENT- It will tell the system to restart and regain the service after the crash and also redeliver the intents that were present at the time of crash happened.

beside this we can have also a little note about START_NOT_STICKY

START_NOT_STICKY- It will tell the system not to worry and bother about to restart the service, even when it is having sufficient available memory.

please visit for more

http://developer.android.com/reference/android/app/Service.html

Jitesh Upadhyay
  • 5,244
  • 2
  • 25
  • 43
  • 1
    will making the service `foreground` keeps away from killing the service (except extreme OOM!) ? – nmxprime Feb 27 '14 at 04:17
  • 1
    It depends how you used,Foreground services can still be killed please visit http://stackoverflow.com/questions/6619143/start-sticky-foreground-android-service-goes-away-without-notice – Jitesh Upadhyay Feb 27 '14 at 04:19
  • I think it would be really clear also if some of you guys explain why the heck name it as STICK and NOT STICKY? At least REDELIVER_INTENT is very intuitive to make sense of, but the other two? Not so much. Why is it called stick and not sticky? – Neon Warge Nov 06 '16 at 05:49
-2

If you are overriding onstartCommand() method, its your responsibility to stop it when not needed by calling stopSelf() or stopService() command.

Balvir Jha
  • 47
  • 2