Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what to return in onStartCommand for a service

Tags:

java

android

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);

like image 791
user3240944 Avatar asked Feb 21 '14 17:02

user3240944


1 Answers

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.

like image 61
Merlevede Avatar answered Oct 01 '22 12:10

Merlevede