i有一项服务,每1-3秒左右接收一次位置更新。服务是使用未决的意图从主要活动中启动的:
mFusedLocationClientFast.requestLocationUpdates(mLocationRequest, getPendingIntent());
其中getPendingIntent()
是为我的IntentService
定义要在handleIntent()
中处理的操作的方法
但是,我注意到的一件奇怪的事是,每次IntentService
处理handleIntent()
中的位置更新时,总是总是在调用同一服务的onStartCommand()
之前。
有人知道为什么每次服务处理意图时都需要调用onStartCommand()
吗?谢谢
IntentService简单来说是在工作线程上运行onHandleIntent
的服务。服务接收意图的机制是onStartCommand
。
在IntentService中,onStartCommand
方法将意图转发到onHandleIntent
方法。
代码为here
[令我感到困惑的是,IntentService
的设计人员没有实现onStartCommand
和onStart
final
]的实现>