Android中Service类的onStartCommand有4种返回值解释如下:
过程如下:
onCreate
onStartCommand
onCreate
onStartCommand startId + 1 ,intent = null
过程如下:
onCreate
onStartCommand
没了
过程如下:
onCreate
onStartCommand
onCreate
onStartCommand startId不变,inutent != null
过程如下:
onCreate
onStartCommand
onCreate
我们再来看一下Service 源码里面,onStartCommand 方法的原型
public int onStartCommand(Intent intent, int flags, int startId) {
onStart(intent, startId);
return mStartCompatibility ? START_STICKY_COMPATIBILITY : START_STICKY;
}那么mStartCompatibility值是什么呢?mStartCompatibility =
getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.ECLAIR;可以看出,只要我们的应用程序 targetSdkVersion 小于 2.0
那么就返回 START_STICKY_COMPATIBILITY,否则返回 START_STICKY
4万+



被折叠的 条评论
为什么被折叠?



