如果pendingintent调用getService()来多次启动一个活动的后台服务该怎么办?



如果PendingIntent调用getService()来启动后台服务(这是活的)多次怎么办?我的猜测是,后台服务仍将存在,除了onStartCommand(意图意图,int标志,int startId)将被多次调用,正确吗?

在我的情况下,我试图调用requestActivityUpdates()来检测用户的活动(移动,静止,…)。当检测到活动(调用回调函数)时,这里的示例(https://github.com/googlesamples/android-play-location/tree/master/ActivityRecognition)使用pendingintent调用intentservice来提取检测到的活动的结果,然后将其广播出去。由于我需要在后台服务中处理这些检测到的活动,我在想我是否可以使用pendingintent直接启动后台服务,而不是调用intentservice并将其广播到我的服务。

我的猜测是,后台服务仍将存在,除了onStartCommand(意图意图,int标志,int startId)将被多次调用,正确吗?

如果服务仍在运行,则在运行的实例上调用onStartCommand()

最新更新