Android Location Listener (or Android events in general)

I have a general question about LocationListener in Android. Perhaps it is about the events of Android or Java in general, but not sure.

There seem to be a million ways to tweak the LocationListener, and they all seem pretty ugly (mainly due to the lack of reuse). Here is an example from android found here :

// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
      // Called when a new location is found by the network location provider.
      makeUseOfNewLocation(location);
    }

    public void onStatusChanged(String provider, int status, Bundle extras) {}

    public void onProviderEnabled(String provider) {}

    public void onProviderDisabled(String provider) {}
  };

// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

This works, but I'm really surprised that this is the standard way to write OOP code ...

, , - LocationListener. - , ? , , gps-... , ? !

+5

All Articles