方法 startSightManagement() 在我的程序中被调用了两次,所以我有两个位置管理器对象。
    private void startSightManagement() {
    String locationService = Context.LOCATION_SERVICE;
    locationManager = (LocationManager)getSystemService(locationService);
    // Get the GPS provider and request location updates
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(true);
    provider = locationManager.getBestProvider(criteria, true);
    locationManager.requestLocationUpdates(provider, 2000, 2, this);
    // Obtain last known location and update the UI accordingly
    Location location = locationManager.getLastKnownLocation(provider);
    updateWithNewLocation(location);
    sightManager = new SightManager(this);
    // Set up the first sight
    setSight();
}
我的 onPause() Activity 与 removeUpdates(this)-->这只会删除一个实例,我如何删除另一个实例?
protected void onPause() {
    myLocationOverlay.disableMyLocation();
    locationManager.removeUpdates(this);
    locationManager=null;
    // TODO Auto-generated method stub
    super.onPause();
    //Shutdown TTS everytime when activity is paused(Tolga)
    if (mTts != null) {
        mTts.stop();
    }
    // Unregister the proximity intent receiver. This also prevents the app from 
    // leaking when it is closed.
    if (proximityIntentReceiver!=null) {
        unregisterReceiver(proximityIntentReceiver);            
    }
}
第二个问题是:启动时未启用 gps 时应用程序崩溃,当询问是否应启用 gps 时我单击“是”。当我删除这两行时,一切正常:
locationManager.removeUpdates(this);
    locationManager=null;
如果在启动时未启用 gps,这是 buildAlert 方法:
    private void buildAlertMessageNoGps() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);  
    builder.setMessage("GPS ist deaktiviert. Standorteinstellungen anzeigen?")
    .setCancelable(false)
    .setPositiveButton("Ja", new DialogInterface.OnClickListener() {
        public void onClick(final DialogInterface dialog, final int id) {
            startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), ENABLE_GPS_SUB);
        }
    })
    .setNegativeButton("Nein", new DialogInterface.OnClickListener() {
        public void onClick(final DialogInterface dialog, final int id) {
            dialog.cancel();
            finish();
        }
    });
    final AlertDialog alert = builder.create();
    alert.show();
}