Are Android geofences surviving a reboot?
Asked Answered
P

3

15

is the system persisting them or do I have to add them again them after reboot? I have not found anything about that in the documentation at https://developer.android.com/training/location/geofencing.html

Pali answered 11/6, 2013 at 9:35 Comment(1)
Please see my answer to a similar question for a complete run down of all of the situations in which you need to re-register geofences.Sixty
I
19

Geofences will not persist on reboot.

You have to listen for BOOT_COMPLETED action and add geofences again.

Note: If your app installed on external storage(SD card), you will never receive Boot Complete action. So you have to specify android:installLocation="internalOnly" in the manifest tag. This is because, android device will broadcast BOOT_COMPLETED action before setting up the external storage.

Iconoduly answered 4/12, 2013 at 5:8 Comment(4)
Hi, in this developer.android.com/training/location/geofencing.html tutorial i really don't understand the usage of SharedPreferences because they are never used in term of accessing data. Do you know why Presistent Storage is used.Geologize
When ever you get triggered from Geofence, you'll get id of that particular geofence. But in real time we have lots of information instead of just an id. SharedPreferences is just like storage to save ousr geofences information like id, messages, lat,lng,and few more values associated with it.Iconoduly
Thanks Sundeep that's sound logical. I'm already storing Geofence data in the database. I was just confused and assuming that may be GeoFence Api use the data that have been saved in the SharedPreferences.Geologize
The default is android:installLocation="internalOnly" so it doesn't need to be explicitly declared in your manifest, but it's not a bad idea to do so.Sax
O
5

I haven't found any documentation confirming this, but my own experiments have shown that they are not persisted across reboots.

My setup was as follows:

  • Run application
  • Application sets up various geofences on first launch only as NEVER_EXPIRE
  • Exit application
  • Use phone in regions marked by fences
  • Confirm fences trigger pending intents which are sent to IntentService
  • Leave region
  • Reboot phone
  • Re-enter region
  • Pending intent does not get sent to IntentService

If anyone has more information on this from someone at Google please comment!

Ochoa answered 17/10, 2013 at 4:26 Comment(1)
You have to add the geofences again on reboot. As the documentation says that geofences are removed on reboot.Gond
J
-1

Which data do you want to persist? Is it the geofence region in your device or the geofence region stored by Google Play Service Location API ?

I believe the device need to register a region (defined by its latitude, longitude and radius) to Google Play Service (via LocationClient). You also need to provide expiration time, transition type you want to be notified, and the Intent from which you will be notified.

This region will be stored (remotely) not in your App. When it pass its expiration time, Google Play Service will automatically remove it. You can also set it as NEVER_EXPIRE. If the region is not expired yet, Google Play Service will notify your App (via intent that you send when calling addGeofences).

The source of the region (lat, long, radius) is up to your implementation.

Joannejoannes answered 2/7, 2013 at 1:26 Comment(4)
Look at these documentations: developer.android.com/reference/com/google/android/gms/location/… and [developer.android.com/reference/com/google/android/gms/location/…>, android.app.PendingIntent, com.google.android.gms.location.LocationClient.OnAddGeofencesResultListener)]Joannejoannes
I just took another look at the GeofencingDetection sample app.Joannejoannes
I just took another look at the GeofencingDetection sample app. It does not need INTERNET permission, only ACCESS_FINE_LOCATION. So the geofencing region most likely stored locally. But, i did not get notified for any transitions when Wifi and 3G are disabled. I am assuming with GPS is the most accurate one, i should get notified for transitions.Joannejoannes
The question asks whether the system (I assume he means Google Play Services) persists Geofences after a reboot, regardless of expiration time, but you don't answer this.Psychasthenia

© 2022 - 2024 — McMap. All rights reserved.