I have a class that processes the location service MyLocationManager.java
this is the code:
package com.syariati.childzone; import java.util.List; import java.util.Locale; import android.content.Context; import android.location.Address; import android.location.Criteria; import android.location.Geocoder; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.widget.Toast; public class MyLocationManager { private Context context; private double myLat = 0.0; private double myLon = 0.0; private LocationManager locationManager = null; private Location location = null; private Criteria criteria; private String locationName = null; public MyLocationManager(Context ctx) { this.context = ctx; } private String setCriteria() { this.criteria = new Criteria(); this.criteria.setAccuracy(Criteria.ACCURACY_FINE); this.criteria.setAltitudeRequired(false); this.criteria.setBearingRequired(false); this.criteria.setCostAllowed(true); this.criteria.setPowerRequirement(Criteria.POWER_LOW); return locationManager.getBestProvider(criteria, true); } public double getMyLatitude() { return this.myLat; } public double getMyLongitude() { return this.myLon; } public String getLocation() { return this.locationName; } public void onLocationUpdate() { locationManager = (LocationManager) context .getSystemService(Context.LOCATION_SERVICE); String provider = setCriteria(); location = locationManager.getLastKnownLocation(provider); updateWithNewLocation(location); locationManager.requestLocationUpdates(provider, 1000, 0, new MyLocationListener()); } private void updateWithNewLocation(Location location) { if (location != null) { this.myLat = location.getLatitude(); this.myLon = location.getLongitude();
which has an Inner class that implements a location receiver on it. While this is working. Listen to this place without any problems. However, when I exit my applications, it does not completely stop listening to the location. As you can see from this code:
@Override public void onLocationChanged(Location newLocation) {
while the location is being updated, the toast will be displayed, and it still appears when the location is being updated. Even when I closed the application.
How to stop the location listener completely in my case.
This helped me stop the update:
android how to stop gps
farissyariati
source share