使用ResultReceiver时无法从IntentService提取GeofencingEvent

时间:2018-08-29 08:13:53

标签: android android-broadcastreceiver android-geofence android-intentservice

我已经实现了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类?

0 个答案:

没有答案