安卓服务中的START_STICKY_COMPATIBILITY标志是什么?文档中提到了
兼容性版本的START_STICKY,它不能保证onStartCommand(意图,int,int)在被杀死后再次被调用。
什么是兼容版本?如果它是START_STICKY的一个版本,那么为什么对onStartCommand()的调用没有得到保证呢?如果它不能保证在服务终止后调用onStartCommand(),那么为什么会有人使用它呢?
发布于 2016-09-02 07:59:35
onStartCommand的默认实现
public @StartResult int onStartCommand(Intent intent, @StartArgFlags int flags, int startId) {
onStart(intent, startId);
return mStartCompatibility ? START_STICKY_COMPATIBILITY : START_STICKY;
}mStartCompatibility是这样确定的:
mStartCompatibility = getApplicationInfo().targetSdkVersion
< Build.VERSION_CODES.ECLAIR;在1.6个版本的Service中,没有onStartCommand的实现,只有onStart。在2.1版本中,他们让onStart不再受欢迎。注意参数的不同,在那里引入了flags。
通过这样做,他们将保持与旧系统(PRE)的兼容性,后者期待旧的价值,并支持新系统中的新行为。
https://stackoverflow.com/questions/39279497
复制相似问题