如果PendingIntent多次调用getService()来启动后台服务(现场直播)怎么办? 我的猜测是后台服务仍然存在,除了onStartCommand(Intent intent,int flags,int startId)将被多次调用,是否正确?
在我的情况下,我试图调用requestActivityUpdates()来检测用户的活动(移动,仍然,......)。当检测到活动(调用回调函数)时,此处的示例(https://github.com/googlesamples/android-play-location/tree/master/ActivityRecognition)使用pendingintent调用intentservice来提取那些检测到的活动的结果然后广播它。 由于我需要在后台服务中处理这些检测到的活动,我想我可以使用pendingintent直接启动我的后台服务,而不是调用intentservice并将其广播到我的服务。
答案 0 :(得分:1)
我的猜测是后台服务仍然存在,除了onStartCommand(Intent intent,int flags,int startId)将被多次调用,是否正确?
如果服务仍在运行,将在正在运行的实例上调用onStartCommand()
。