what is the purpose of `setInitialTrigger` on GeofencingRequest?

builder.setInitialTrigge Sets the geofence notification behavior at the moment when the geofences are added.

You can use 3 constants:

public static final int INITIAL_TRIGGER_DWELL

A flag indicating that geofencing service should trigger GEOFENCE_TRANSITION_DWELL notification at the moment when the geofence is added and if the device is already inside that geofence for some time.

Constant Value: 4

public static final int INITIAL_TRIGGER_ENTER

A flag indicating that geofencing service should trigger GEOFENCE_TRANSITION_ENTER notification at the moment when the geofence is added and if the device is already inside that geofence.

Constant Value: 1

public static final int INITIAL_TRIGGER_EXIT

A flag indicating that geofencing service should trigger GEOFENCE_TRANSITION_EXIT notification at the moment when the geofence is added and if the device is already outside that geofence.

Constant Value: 2

What is the meaning of GeofencingRequest.INITIAL_TRIGGER_ENTER ? INdicate that geofencing service should trigger at the moment when the geofence is added and if the device is already inside that geofence.

Check the difference is the time:

DWELL = is already inside that geofence for some time.

ENTER = is already inside that geofence.

EXIT = is already outside that geofence.


You can use

`public GeofencingRequest getGeofencingRequest(Geofence geofence){
        return  new GeofencingRequest.Builder()
                .addGeofence(geofence)
                .setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_DWELL|
                                   GeofencingRequest.INITIAL_TRIGGER_ENTER|
                                   GeofencingRequest.INITIAL_TRIGGER_EXIT)
                .build();
    }`

This function will trigger the GeofenceRequest when either of ENTER, DWELL, EXIT will take place