GPS not update location after close and reopen app on android

Posted by mrmamon on Stack Overflow See other posts from Stack Overflow or by mrmamon
Published on 2009-09-07T15:07:00Z Indexed on 2010/05/22 12:00 UTC
Read the original article Hit count: 243

Filed under:
|

After I closed my app for a while then reopen it again,my app will not update location or sometime it will take long time( about 5min) before update. How can I fix it? This is my code

  private LocationManager lm;
private LocationListener locationListener;

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);    

    lm = (LocationManager) 
        getSystemService(Context.LOCATION_SERVICE);    

    locationListener = new mLocationListener();

    lm.requestLocationUpdates(
        LocationManager.GPS_PROVIDER, 0, 0, locationListener); }


private class myLocationListener implements LocationListener 
{
    @Override
    public void onLocationChanged(Location loc) {
        if (loc != null) {
            TextView gpsloc = (TextView) findViewById(R.id.widget28);
            gpsloc.setText("Lat:"+loc.getLatitude()+" Lng:"+ loc.getLongitude());
        }
    }

    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub
        TextView gpsloc = (TextView) findViewById(R.id.widget28);
        gpsloc.setText("GPS OFFLINE.");
    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onStatusChanged(String provider, int status, 
        Bundle extras) {
        // TODO Auto-generated method stub
    }
}

© Stack Overflow or respective owner

Related posts about android

Related posts about gps