Hello guys,
I have a button, when I press it it calls the method whatIsEnabled() (GPS, Network, or both) and registers a location listener. My problem is when I run it with out the onPause() and on Resume methods is work (working in progress so I an gratefull when it work) but when I put the onPause mothos to unregister the listener it creashes. The code:
- Code: Select all
private OnClickListener location_button = new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
registerLocListener();
}
}
private void createLocListener() {
//locationListener = new Coordonates(drawable, mapView, Map.this);
locationListener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
Toast.makeText(context, "Lat: " + location.getLatitude() + " Lng: " + location.getLongitude() ,Toast.LENGTH_LONG).show();
}
};
}
protected void onResume() {
registerLocListener();
super.onResume();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
locationManager.removeUpdates(locationListener);
super.onPause();
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}

