what to return in onStartCommand for a service
It all depends on what you want. The documentation says:
For backwards compatibility, the default implementation calls onStart(Intent, int) and returns either START_STICKY or START_STICKY_COMPATIBILITY.
So returning super.onStartCommand()
is equivalent to returning START_STICKY
. If you don't want the default behavior you can return another constant.
The most often used are
- Service.START_STICKY
- Service.START_NOT_STICKY and
- Service.START_REDELIVER_INTENT
Service.START_STICKY will restart if the android system terminates for any reason. Service.START_NOT_STICKY will run till it has pending works. Service.START_REDELIVER_INTENT is similar to Service.START_STICKY but the original Intent is re-delivered to the onStartCommand method.