mFusedLocationClientFast.requestLocationUpdates(mLocationRequest, getPendingIntent());
其中getPendingIntent()
是为我的IntentService
定义要在handleIntent()
中处理的动作的方法
但是,我注意到的一件奇怪的事是,每次IntentService
处理handleIntent()
中的位置更新时,总是总是紧接着调用相同服务的onStartCommand()
。 / p>
有人知道为什么每次服务处理意图时都需要调用onStartCommand()
吗?
谢谢
答案 0 :(得分:1)
IntentService简单来说就是在工作线程上运行onHandleIntent
的Service。服务接收意图的机制是onStartCommand
。
在IntentService中,onStartCommand
方法将意图转发到onHandleIntent
方法。
代码为here
令我感到困惑的是,IntentService
的设计者没有实现onStartCommand
和onStart
final