I have been looking through the documentation and sometimes the onStartCommand()
returns START_NOT_STICKY
, sometimes it returns the following:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
return super.onStartCommand(intent, flags, startId);
}
I am now confused as to why some services return super.onStartCommand(intent, flags, startId);
It all depends on what you want. The documentation says:
So returning
super.onStartCommand()
is equivalent to returningSTART_STICKY
. If you don't want the default behavior you can return another constant.The most often used are
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.