What are the methods to stop a class?

0

The problem that occurs to me is that I have a class called Localizacion in which I implement LocationListener with their respective methods onLocationChanged , onProviderDisabled , onProviderEnabled and onStatusChanged , the same one executes practitioner infinitely, and I would like to know how I can stop it after I do only once what it has to do. Here is my class:

public class Localizacion implements LocationListener {

    MainActivity gpsActivity;

    public MainActivity getGpsActivity() {
        return gpsActivity;
    }
    void setGPSActivity(MainActivity gpsActivity) {
        this.gpsActivity = gpsActivity;
    }
    @Override
    public void onLocationChanged(android.location.Location loc) {
        loc.getLatitude();
        loc.getLongitude();
        this.gpsActivity.setLocation(loc);
        }
    @Override
    public void onProviderDisabled(String provider) {
        Toast.makeText(getBaseContext(), "GPS desactivado", Toast.LENGTH_LONG).show();
    }
    @Override
    public void onProviderEnabled(String provider) {
        Toast.makeText(getBaseContext(),"GPS Activado", Toast.LENGTH_LONG).show();
    }
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        switch (status) {
            case LocationProvider.AVAILABLE:
                Log.d("debug", "LocationProvider.AVAILABLE");
                break;
            case LocationProvider.OUT_OF_SERVICE:
                Log.d("debug", "LocationProvider.OUT_OF_SERVICE");
                break;
            case LocationProvider.TEMPORARILY_UNAVAILABLE:
                Log.d("debug", "LocationProvider.TEMPORARILY_UNAVAILABLE");
                break;
        }
    }

public void setLocation(android.location.Location loc) {
    //Obtener la direccion de la calle a partir de la latitud y la longitud
    if (loc.getLatitude() != 0.0 && loc.getLongitude() != 0.0) {
        try {
            Geocoder geocoder = new Geocoder(this, Locale.getDefault());
            List<Address> list = geocoder.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1);
            if (!list.isEmpty()) {
                final Address DirCalle = list.get(0);
                DirCalle.getAddressLine(0);
} catch (IOException e) {
            e.printStackTrace();
        }
    }
    
asked by David Villegas 11.07.2018 в 22:48
source

0 answers