I have been through solutions and found that there are a lot of ways to implement a location tracking logic.
I am trying to find out what would be the best practice(most power efficient way) to achieve the same...
I have a library class MyLocationClass.java which has two methods 1. startTracking() - Start sending user location after T time and only if the user has moved X distance 2. stopTracking() - stop sending location updates.
A simple answer seems to be a LocationListener because of its inbuilt Time Passed/Distance Moved features which provides a better user experience, but then...
I don't want the GPS to be on all the time? In fact it should be only switched on when T and X are crossed. Will using a Service/IntentService and/or/with an alarm manager Timer will be a better solution? Can BroadcaastReceivers with LocationListeners prove to be the better solution?
Please suggest.
I think, you can use the Location Listener implemented in a service. Start listening the GPS when the service starts and remove the GPS listener when the service stops. Start this service when you wants to listen to GPS.
Also please take a look at the "requestLocationUpdates" method. The minTime and minDistance fields of this function is explained as follows:
minTime the minimum time interval for notifications, in milliseconds. This field is only used as a hint to conserve power, and actual time between location updates may be greater or lesser than this value.
minDistance the minimum distance interval for notifications, in meters