In the Android documentation, the Service's "onStartCommand()
" has an intent given as a param
, that according to the docs:
"the Intent
supplied to startService(Intent)
, as given. This may be null if the service is being restarted after its process has gone away, and it had previously returned anything except START_STICKY_COMPATIBILITY
."
However, the return value START_REDELIVER_INTENT
is supposed to return the original intent when restarting a service.
Can anyone explain why an intent
can be null, even if the flag
was set to START_REDELIVER_INTENT
?
Constant to return from onStartCommand(Intent, int, int) : if this service's process is killed while it is started (after returning from onStartCommand(Intent, int, int) ), then it will be scheduled for a restart and the last delivered Intent re-delivered to it again via onStartCommand(Intent, int, int) .
START_STICKY. the system will try to re-create your service after it is killed. START_NOT_STICKY. the system will not try to re-create your service after it is killed. Standard example: @Override public int onStartCommand(Intent intent, int flags, int startId) { return START_STICKY; }
Sticky Services — Sticky service is somewhere between regular service and foreground service Android will kill the process time to time of this service, however it will be created automatically if the resources are available as soon as possible.
Starting a serviceThe Android system calls the service's onStartCommand() method and passes it the Intent , which specifies which service to start. Note: If your app targets API level 26 or higher, the system imposes restrictions on using or creating background services unless the app itself is in the foreground.
Are you possibly confusing START_FLAG_REDELIVERY with START_REDELIVER_INTENT? Your post says, "the return value START_FLAG_REDELIVERY
". That constant is not one of the values returned from onStartCommand, it is one of the bit values passed into onStartCommand
as the flags
parameter. START_FLAG_REDELIVERY
and START_STICKY
both have value of 1. If you mistakenly have return START_FLAG_REDELIVERY
at the end of onStartCommand()
, the service will restart in sticky mode with a null intent if there are no start commends pending.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With