For example let's say you are driving in a car and the LocationManager is connected to a valid GPS provider. Now you driving through a tunnel and lose the signal. Now onLocationChanged()
isn't triggered anymore. But the system will keep searching in background for a valid GPS provider. If you are through the tunnel the system reconnects to the GPS provider, if still available, and onLocationChanged()
is triggered again.
The drain of the battery while connected and getting location updates is much higher as when the system is looking for a valid provider.
If you switch to WiFi or 3G the system will look for the last set provider and overrides the previous one. But the behaviour will be the same.
You can react on this event by monitoring the LocationListener.onStatusChanged()
callback and the GpsStatus.Listener interface. E.g. switch to another provider or if no provider is available call removeLocationUpdates()
and call requestLocationUpdates()
again after a period of time with a Timer
. This will save your battery much better.
Edit:
LocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
returns true if GPS is enabled in the settings of the device. It's no indicator that you are connected to a GPS provider.
Use the method LocationManager.getBestProvider(Criteria, boolean) to know which provider is available.
As a note: You will almost never get a connection to GPS if you are inside of a room.