Reputation: 19562
According to the Location Strategies, GPS is most accurate but quickly consumes battery power. The document recommends that battery power should be among the things to take into account but from that document there is no example of a bad usage.
Could someone please provide such an example.
I am asking because I am thinking of a usecase such as
E.g. if capturing the user location 16 times in a day (in 30 mins intervals). Would that be a bad use case model?
Upvotes: 2
Views: 3316
Reputation: 2234
EDIT
Here is a very basic example of setting up a timeout feature for location requests.
public class MyLocationManager implements LocationListener {
private static final int LOCATION_UPDATE = 1;
private LocationManager mLocationManager;
private Handler mHandler;
public MyLocationManager(Context context) {
mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
mHandler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
switch (msg.what) {
case LOCATION_UPDATE:
stopLocationUpdates();
return true;
default:
return false;
}
}
});
}
public void stopLocationUpdates() {
mLocationManager.removeUpdates(this);
mHandler.removeMessages(LOCATION_UPDATE);
}
public void requestLocationUpdates(long timeOut) {
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
mHandler.sendEmptyMessageDelayed(LOCATION_UPDATE, timeOut);
}
@Override
public void onLocationChanged(Location location) {
stopLocationUpdates();
//YOUR CODE HERE
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
}
To answer the title of your post: It varies based on the device.
To get into more detail, it really depends on how you set up your requests. In your case, you say you want 16 points in 30 minute intervals, which won't put much impact on power if you receive them all within a second of the request. However, you never specified how long you would wait for the location to arrive or what the accuracy of location point you were requesting should be. So in theory, you could keep the GPS module running indefinitely if you are looking for 10m accuracy points in a basement.
My recommendation
Find out the max accuracy of a location point you need before it is completely unusable, and have a solid timeout feature in place. GPS by itself doesn't kill the battery, it's the combination of the device being awake to receive the location and the GPS module being on that kills battery life. Keeping the device on for ~2 min total to receive 16 points (~8 second timeout) should have negligible impact on battery.
Upvotes: 1