16

The question is in the title. Do the new Android Geofences get removed if the app is killed by the user?

I am using the new Android Geofences (announced at Google IO 2013). I can't quite work out if the app's Geofences get removed if the user removes/kills the app using the Android task manager. I think with the old addProximityAlert technique they were not removed.

Tim
  • 5,767
  • 9
  • 45
  • 60
  • 2
    Why the vote down? The documentation doesn't give any indication as to what happens if the app is killed. The Geofences are managed by Google Play services so I can't tell if an app being killed flushes its Geofences out. – Tim May 21 '13 at 14:40
  • 1
    The incumbent general rule for the past few releases has been that an app which has been force killed from the settings menu can not run again until started again by explicit user interaction, so allowing geofences to start it again would seem to be a major departure from the existing philosophy. It doesn't seem like it would be too hard to test. – Chris Stratton May 21 '13 at 15:19
  • Thanks Chris. That does seem sensible alright. I will test that later. I want to do a real world test (rather than mock location) which means a bit of walking and rechecking the logcat. – Tim May 21 '13 at 15:31
  • 3
    I just ran a test based on AlarmManager and I have to disagree with Chris. I set an alarm with my app three minutes into the future, killed the app and three minutes later my app showed the notification. I bet the same basic mechanism applies for Geofences, too. After all you register these alarms with a central service provided by the OS. Killing your app process does not automatically remove these alarm registrations. The only time you lose these alarm registrations is when the system reboots. Therefore you need to re-create them on system startup. – tiguchi Aug 07 '13 at 20:07

3 Answers3

4

As declared here:

The app must re-register geofences if they're still needed after the following events, since the system cannot recover the geofences in the following cases:

The device is rebooted. The app should listen for the device's boot complete action, and then re- register the geofences required.
The app is uninstalled and re-installed.
The app's data is cleared.
Google Play services data is cleared.
The app has received a GEOFENCE_NOT_AVAILABLE alert. This typically happens after NLP (Android's Network Location Provider) is disabled.
heartear
  • 73
  • 1
  • 8
2

I believe the answer to this is no. A registered Geofence will not get removed if the user kills the app, if the app crashes or if the app is killed by a task manager. I know that is you register a Geofence with the flag NEVER_EXPIRE the Geofence registration will stay even if the application is uninstalled.

My understanding is the registered Geofence must reach expiration or be de-registered in order to be removed without rebooting the phone.

Darkcylde
  • 849
  • 5
  • 17
  • Thank you @Darkcylde I'll mark this as the answer soon unless someone diasagrees. – Tim Aug 08 '13 at 15:33
  • 1
    I disagree - this is not documented anywhere and this is just a guess - please don't propagate guessing as answers on SO. – Marian Paździoch Sep 03 '15 at 13:25
  • 1
    Wasn't a guess. This was ascertained by trying out each scenario and checking what happened. I didn't state that it was documented and I think the wording clearly suggest that my assertions are based on experience. It is also worth noting this was quite a while ago on an old version of android. The latest version may work differently. – Darkcylde Sep 04 '15 at 03:14
2

From my testing this isn't the case. They get removed when uninstalling the app.

Google really needs to have an api that lets you get all the fences you have registered... That would make things much better.

b-ryce
  • 5,752
  • 7
  • 49
  • 79