令人困惑的是,FusedLocationProviderApi 停止发送意图。
更详细一点:我有一个构建 GoogleApiClient 的 Android 服务。
mClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addApi(ActivityRecognition.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mClient.connect();
连接后,我使用以下命令请求位置更新:
// Set up periodic location updates
Intent locationIntent = new Intent(this, LocationReceiver.class);
mLocationPendingIntent = PendingIntent.getBroadcast(
this,
0,
locationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
mFusedLocationProviderApi.requestLocationUpdates(
mClient,
mLocationRequest,
mLocationPendingIntent);
我请求使用以下方法检测到的活动:
// Set up activity recognition
Intent activityRecognizedIntent = new Intent(
this,
ActivityRecognizedReceiver.class);
mActivityRecognizedPendingIntent = PendingIntent.getBroadcast(
this,
0,
activityRecognizedIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
mActivityRecognitionApi.requestActivityUpdates(
mClient,
ACTIVITY_DETECTION_INTERVAL,
mActivityRecognizedPendingIntent);
当服务被操作系统杀死时,例如当我将新版本的应用程序推送到我的手机时,ActivityRecognizedReceiver 会继续接收更新!我怎样才能阻止这种情况发生?为什么 LocationReceiver停止接收更新?