Geofence understanding Geofence lifetime

505 views Asked by At

I've built Geofence as:

    GeofenceModel modelExit = new GeofenceModel.Builder("id_oi_456")
                .setTransition(Geofence.GEOFENCE_TRANSITION_DWELL)
                .setExpiration(Geofence.NEVER_EXPIRE)
                .setLatitude(40.414341)
                .setLongitude(49.928548)
                .setRadius(CLIENT_GEOFENCE_RADIUS)
                .build();


    SmartLocation.with(this).geofencing()
                .add(modelExit)
                .start(this);

When set to NEVER_EXPIRE, it gets triggered. When setExpiration() is not set geofence will not be triggered though. The question is that What isdefault expiration time for single geofence?

2

There are 2 answers

0
shocking On

In regards to Android's Geofence class: it is not possible to create a Geofence using Geofence.Builder without setting an expiration. If you try to, it will throw java.lang.IllegalArgumentException: Expiration not set.

As for your GeofenceModel class, I'm not sure.

0
keriackus On

Assuming you're using com.google.android.gms.location.Geofence underneath your GeofenceModel class.

You have an instance variable named modelExit indicates that you're waiting for the exit transition. while in your geofence configuration you're only listening to GEOFENCE_TRANSITION_DWELL. You should set the transition to GEOFENCE_TRANSITION_EXIT.