START_STICKY_COMPATIBILITY in services

What is the START_STICKY_COMPATIBILITY flag in terms of Android services. The documentation mentions him

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

What is the compatibility version? And if its version is START_STICKY , then why is the call to onStartCommand() not guaranteed? And why would anyone use it if it does not guarantee that onStartCommand() ever called after the service is killed?

+5
source share
1 answer

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

mStartCompatibility defined as follows:

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

In version 1.6 Service the onStartCommand implementation onStartCommand not exist onStart . In version 2.1, they made onStart obsolete. Pay attention to the difference in the parameters, flags were introduced there.

Thus, they will maintain compatibility with the old system (PRE Eclair), which expects the old value, and also supports new behavior on newer systems.

+7
source

All Articles