在我关闭我的应用程序一段时间然后再次打开它后,我的应用程序将不会更新位置,或者有时需要很长时间(大约 5 分钟)才能更新。我该如何解决?这是我的代码
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
}
}