Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Android Geofences remain active until removed/expired or only until my PendingIntent is launched

I'm about to implement a feature with geofences and before I get any serious work done, I need to know whether geofences remain active after the first transition.

The core of the feature is:

every time I'm within x meters of point P (call this Area A), I want Action B to occur.

What I need to know is

  • Do I just have to add a geofence with Geofence.NEVER_EXPIRE and rest assured that I will get a PendingIntent every time I enter the specified area regardless of elapsed time, reboots, etc

OR

  • Do I have to re-register this geofence once I exit Area A in order to get notified the next time I enter Area A?

I'm hoping that the former is the case

like image 511
copolii Avatar asked Jul 24 '13 09:07

copolii


2 Answers

The good proposition is the first one. If you create a geofence with the flag NEVER_EXPIRE as expiration time, you won't have to re-register it when it is triggered (by going in or out). I'm 100% certain of this, I'm right now just finished coding and testing a POC about geofence.

From the doc, the only way for a geofence to be deleted is either expiration time is reached or it is deleted by the device itself.

Expiration time

How long the geofence should remain active. Once the expiration time is reached, Location Services deletes the geofence. Most of the time, you should specify an expiration time, but you may want to keep permanent geofences for the user's home or place of work.

To stop geofence monitoring, you remove the geofences themselves

like image 107
Marcel Falliere Avatar answered Oct 10 '22 01:10

Marcel Falliere


Please remember that NEVER_EXPIRE will cause the geofence to be registered even after a user uninstalls the app in case the app doesn't uninstall them. There is no way to remove these. Ever. So they will keep draining battery. Therefore, setting an expiration time is advisable and to set the geofence again in case they expire before you want them to.

like image 26
hajons Avatar answered Oct 10 '22 00:10

hajons