Difference between START_STICKY and START_REDELIVER_INTENT?

前端 未结 3 1959
盖世英雄少女心
盖世英雄少女心 2020-12-09 17:30

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 p

相关标签:
3条回答
  • 2020-12-09 17:37

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

    0 讨论(0)
  • 2020-12-09 17:39

    START_NOT_STICKY:

    If the system kills the service after onStartCommand() returns, do not recreate the service unless there are pending intents to deliver. This is the safest option to avoid running your service when not necessary and when your application can simply restart any unfinished jobs.

    START_STICKY:

    If the system kills the service after onStartCommand() returns, recreate the service and call onStartCommand(), but do not redeliver the last intent. Instead, the system calls onStartCommand() with a null intent unless there are pending intents to start the service. In that case, those intents are delivered. This is suitable for media players (or similar services) that are not executing commands but are running indefinitely and waiting for a job.

    START_REDELIVER_INTENT:

    If the system kills the service after onStartCommand() returns, recreate the service and call onStartCommand() with the last intent that was delivered to the service. Any pending intents are delivered in turn. This is suitable for services that are actively performing a job that should be immediately resumed, such as downloading a file.

    0 讨论(0)
  • 2020-12-09 17:59

    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

    0 讨论(0)
提交回复
热议问题