Reputation: 2196
I want to receive gps data like every 3 minutes from a service over a long time (3-4 hours). It all works fine but I have some questions to which method is the best regarding battery lifetime.
Start the service, inside onCreate of the service create a partial wakelock, start a timer that is executed every 3 minutes. Get position data from inside the timer. When the service is stopped (after 3-4 hours) release the wake lock.
Use AlarmManager to start the service every 3 minutes. Inside the service create a partial wakelock, get the position data and then release the wake lock and stop the service.
Same as #1 but instead of a timer set the intervall through the requestLocationUpdates() method. (The reason why I don't like this method is that when I use a timer I can get like 5 positions (every 3 minutes) and pick the most accurate but when I set the intervall with requestLocationUpdates() I only get one position, which might be inaccurate, or am I wrong?)
I don't like the idea of leaving a partial wakelock for 3-4 hours thats why I think that #2 might be a better solution.
Upvotes: 1
Views: 875
Reputation: 115
// The minimum distance to change Updates in meters
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters
// The minimum time between updates in milliseconds
private static final long MIN_TIME_BW_UPDATES = 1000; // 1 sec
LocationManager locationManager; locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Upvotes: 5