Android - Gps Listener
I am developing an Android application which consists a few activities. I want to get updates from the GPS (onLocationChanged, onProviderDisabled, onProviderEnabled, onStatusChange
Solution 1:
Start the location listener on the activity you wants to start the gps. To start the GPS you can use
LocationManagerlocationManager= (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListenerlocationListener=newCTLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1.0f, locationListener);
and to stop the GPS you can use
locationManager.removeUpdates(locationListener);
Its better you write the GPS start on the onCreate()/onStart() and the GPS remove on the onDestroy() of a service and use that service. Otherwise once you stop the GPS the chance of starting the GPS again is less than 50% in some devices.
Solution 2:
Create a Service and monitor location there or you can implement a LocationListener in a separate class and use it in every Activity, turning it on onResume() and shutting down onPause()
Post a Comment for "Android - Gps Listener"