Note that there are some explanatory texts on larger screens.

plurals
  1. POrequestLocationUpdates parameters having no effect on Gingerbread device
    primarykey
    data
    text
    <p>I had previously coded an app with a location listener without access to a real device. Now that I have a Gingerbread phone (2.3.3), as expected my app is a battery killer.</p> <p>I started examining the effect of the update time and minimum distance arguments to requestLocationUpdates as the documentation says that these will affect battery drain.</p> <p>I had wondered how just adjusting these parameters could affect the battery drain, as far as I could see the GPS would have to remain on, in order to know what distance the device had moved and only the actual process of notifying the app would change whilst the chip continued using power.</p> <p>This article <a href="http://blog.doityourselfandroid.com/2010/12/25/understanding-locationlistener-android/" rel="nofollow">Understanding the LocationListener in Android</a> put forward a credible explanation, indicating that the status would change to 'temporarily unavailable' and the GPS icon would disappear from the screen for a while, until such time as it was necessary to turn back on again according to the update period specified.</p> <p><strong>This doesn't happen on my phone - the GPS icon stays on even with an update period of 90 seconds and I get no status changes</strong> and according to some of the posts at the end of the article, others find the same.</p> <ul> <li><p>Do any users on SO experience the same thing with 2.3.3?</p></li> <li><p>Or have Android given up on managing the GPS chip and expect users to write their own battery management regime for the GPS?</p></li> </ul> <p>For info my minimum code to demonstrate this behaviour is shown below:</p> <pre><code>public class GpsTimeOutTestActivity extends Activity implements LocationListener { private LocationManager mLocMgr; private long mUpdatePeriod = 90000; // 90 seconds private float mMinDistance = 10.0f; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } @Override protected void onResume() { super.onResume(); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); mLocMgr = (LocationManager) getSystemService(LOCATION_SERVICE); mLocMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, mUpdatePeriod, mMinDistance, (LocationListener) this); } @Override protected void onPause() { mLocMgr.removeUpdates((LocationListener) this); super.onPause(); } @Override public void onLocationChanged(Location loc) { String str = null; NumberFormat formatter = new DecimalFormat("##0.000"); String fLat = formatter.format(loc.getLatitude()); String fLon = formatter.format(loc.getLongitude()); String provider = loc.getProvider(); provider = (provider == null) ? "No provider" : provider; str = "Locn chg " + provider + " Lat/Lon " + fLat + "/" + fLon; if (loc.hasAccuracy()) str+= " accy " + loc.getAccuracy(); showSomeOutput(str); } @Override public void onProviderDisabled(String provider) { String str = "Prov disabled " + provider; showSomeOutput(str); } @Override public void onProviderEnabled(String provider) { String str = "Prov enabled " + provider; showSomeOutput(str); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { String str = "Status chg " + provider; switch (status) { case android.location.LocationProvider.OUT_OF_SERVICE: str+= " OUT OF SERVICE"; break; case android.location.LocationProvider.AVAILABLE: str+= " AVAILABLE"; break; case android.location.LocationProvider.TEMPORARILY_UNAVAILABLE: str+= " TEMPORARILY UNAVAILABLE"; break; default: str+= " UNKNOWN STATUS"; } showSomeOutput(str); } private void showSomeOutput(String str) { Log.d("GPSTEST", str); EditText et = (EditText) findViewById(R.id.editText1); Editable existingText = et.getText(); existingText.append("\n" + str); } } </code></pre> <p>All comments will be gratefully received.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload