I am having problems with LocationListenerin my service called myService.
Here is my code:
onStart() {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE)
.
.
provider = locationManager.getBestProvider(criteria, true);
locationListener = (LocationListener) new MyLocationListener();
locationManager.requestLocationUpdates(provider, 0, 0, locationListener);
}
In my activity there is a button that should stop the service. I click the button that I am doing:
stopService(new Intent(getApplicationContext(), myService.class)
In the file myService.javaI have:
onDestroy() {
locationManager=(LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.removeUpdates(locationListener);
}
I get the following exception:
java.lang.IllegalArgumentException: listener==null at android.location.LocationManager.removeUpdates(LocationManager.java:799) at
<.package_name>myService.onDestroy(myService.java:407)
I do not know why the listener goes to zero for no reason. Please tell me where I am going wrong!
sheik source
share