我已经实现了IntentService
,它正在接收GeoFencing
转换(进入/退出)的事件。为了更新有关这些过渡的activity
,我在传递给ResultReceiver
的意图中传递了一个'PendingIntent
':
intent = new Intent(appContext, GeofenceTransitionsIntentService.class);
intent.putExtra("geofencetransitionlistener",new ResultReceiver(new Handler()) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
if(resultCode == Geofence.GEOFENCE_TRANSITION_ENTER) {
dataListener.onGeoFenceLocationEnter();
} else if(resultCode == Geofence.GEOFENCE_TRANSITION_EXIT) {
dataListener.onGeoFenceLocationExit();
}
}
});
mGeofencePendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.
FLAG_UPDATE_CURRENT);
mGeofencingClient.addGeofences(getGeofencingRequest(), getGeofencePendingIntent());//also added success,failure listeners
发生Geofencing
转换时,我无法正确接收GeofencingEvent
(获取
错误代码-1,不返回getTriggeringGeofences()的列表。
未通过ResultReceiver
时,GeofencingEvent
正常工作。
就像ResultReceiver不适用于GeoFencing一样,那么是否有其他替代解决方案可用于将过渡传递回activity
类?