@@ -293,23 +293,25 @@ private void updateTrackedGeofences() {
293293 LocationServices .GeofencingApi .addGeofences (googleApiClient ,
294294 request , getTransitionPendingIntent ());
295295 for (Geofence geofence : toBeTrackedGeofences ) {
296- trackedGeofenceIds .add (geofence .getRequestId ());
297- //TODO: stateBeforeBackground doesn't get persisted.
298- // If the app goes to the background and terminates, stateBeforeBackground will be reset.
299- if (isInBackground && !Util .isInBackground () && stateBeforeBackground != null
300- // This is triggered only for in-app messages, since backgroundGeofences are only for
301- // pushes.
302- // TODO(aleks): This would not work for in-app messages if we have the same geolocation
303- // triggering it, as a locally triggered push notification.
304- && !backgroundGeofences .contains (geofence )) {
305- Number lastStatus = (Number ) stateBeforeBackground .get (geofence .getRequestId ());
306- Number currentStatus = (Number ) lastKnownState .get (geofence .getRequestId ());
307- if (currentStatus != null && lastStatus != null ) {
308- if (GeofenceStatus .shouldTriggerEnteredGeofence (lastStatus , currentStatus )) {
309- maybePerformActions (geofence , "enterRegion" );
310- }
311- if (GeofenceStatus .shouldTriggerExitedGeofence (lastStatus , currentStatus )) {
312- maybePerformActions (geofence , "exitRegion" );
296+ if (geofence != null && geofence .getRequestId () != null ) {
297+ trackedGeofenceIds .add (geofence .getRequestId ());
298+ //TODO: stateBeforeBackground doesn't get persisted.
299+ // If the app goes to the background and terminates, stateBeforeBackground will be reset.
300+ if (isInBackground && !Util .isInBackground () && stateBeforeBackground != null
301+ // This is triggered only for in-app messages, since backgroundGeofences are only for
302+ // pushes.
303+ // TODO(aleks): This would not work for in-app messages if we have the same geolocation
304+ // triggering it, as a locally triggered push notification.
305+ && !backgroundGeofences .contains (geofence )) {
306+ Number lastStatus = (Number ) stateBeforeBackground .get (geofence .getRequestId ());
307+ Number currentStatus = (Number ) lastKnownState .get (geofence .getRequestId ());
308+ if (currentStatus != null && lastStatus != null ) {
309+ if (GeofenceStatus .shouldTriggerEnteredGeofence (lastStatus , currentStatus )) {
310+ maybePerformActions (geofence , "enterRegion" );
311+ }
312+ if (GeofenceStatus .shouldTriggerExitedGeofence (lastStatus , currentStatus )) {
313+ maybePerformActions (geofence , "exitRegion" );
314+ }
313315 }
314316 }
315317 }
0 commit comments