Hello I am trying to add feature of Geo Fence in Android. I am using the http://developer.android.com/training/location/geofencing.html for creating and monitoring Geo Fence
I also had problems with the geofence system jumping in and out of my geofences and then i read this (Quote from official docs):
There is no reliable network connectivity inside your geofence. If there is no reliable data connection, alerts might not be generated. This is because the geofence service depends on the network location provider which in turn requires a data connection.
From the official geofence documentation
If che device is not connected to internet google play services (like geofence or activityrecognition) don't work.
I summarized the best practices from several StackOverflow threads regarding Geofencing in Android in a sample project on Github called Geofencer. This can be used to as a reference to implement GeoFencing into your application. It also allows to switch to a 3rd party GeoFencing implementation on the fly. I hope this is helpful for some of you!
I've found that the GeoFencing never intelligently retrieves locations from the GPS hardware. The GeoFence API will observe the most accurate location available from the OS or if no recent location reading is available, it will cause a location to be calculated from Wifi / Cellular. (which sucks because cellular is wildly inaccurate and wifi is often unavailable)
So to get at all responsive or accurate results out of the Geofencing API you have to set up your Geofences and then poll the GPS hardware on an interval, not even doing anything with the result received, so that under the surface you are providing worthwhile data to the OS.
This is probably at the core of why your results are inaccurate. The geofence exit won't trigger until the OS is sure you're 100% outside the fence - so if a location reading has an accuracy of 500 meters (not improbable when using cell geolocation) and your fence has a radius of 50m you'd have to be at least 550m from your fence point to produce an exit event.
TLDR; Poll the GPS hardware on an interval without doing anything with the result and you'll start getting more accurate geofences.
Android's native geofencing is shockingly inaccurate and battery intensive. I suggest you use a third-party tool like Bluedot's Point SDK (accurate to 10m/30 feet) or Gimbal's SDK (accurate to 50m/165 feet), both of which are much more reliable with less battery drain.
Full disclosure: I work for Bluedot.