9

What is START_STICKY_COMPATIBILITY flag in terms of Android Services. The documentation mentions it

compatibility version of START_STICKY that does not guarantee that onStartCommand(Intent, int, int) will be called again after being killed.

What is compatibility version? And if its a version of START_STICKY, then why is the call to onStartCommand() is not guaranteed?And why will anyone use it when it doesn't guarantee that onStartCommand() is ever called after the service is killed?

2

1 Answer 1

14

The default implementation of onStartCommand:

  public @StartResult int onStartCommand(Intent intent, @StartArgFlags int flags, int startId) {
        onStart(intent, startId);
        return mStartCompatibility ? START_STICKY_COMPATIBILITY : START_STICKY;
    }

The mStartCompatibility is determined this way:

 mStartCompatibility = getApplicationInfo().targetSdkVersion
                < Build.VERSION_CODES.ECLAIR;

In the 1.6 version of the Service there is no implementation of onStartCommand only onStart. In the version of 2.1 they made the onStart deprecated. Notice the difference in the parameters, flags was introduced there.

By doing this, they will maintain compatibility with older system(PRE Eclair) which expects the old value and they also support the new behaviour in newer systems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.