Good day, respected community.
I write applications for defining geo-coordinates in the background (Service):
Public Class GeoService Extends Service Implements LocationListener {
Locationmanager lm;
Public Ibinder Onbind (Intent Arg0) {
RETURN NULL;
}
Public void oncreate () {
LM = (LocationManager) GetSystemSystemVice (Location_Service);
lm.requestlocationUpdates (locationmanager.gps_provider,
60000, 0, this); // Trying to get the data every 60 seconds
}
Public Void OnlocationChanged (location location) {
// Received the required data:
Double Latitude = location.getlatitude ();
Double Longitude = location.getlongitude ();
if_refresh) {// One-time event that signals updating parameters
lm.removeUpdates (this);
lm.requestlocationUpdates (locationmanager.network_provider,
120000.0, this);}
}
Public Void OnProviderDisabled (String Provider) {
// TODO AUTO-GENERATED METHOD STUB
}
Public void onproviderenabled (String Provider) {
// TODO AUTO-GENERATED METHOD STUB
}
Public Void OnStatusChanged (String Provider, Int Status, Bundle Extras) {
// TODO AUTO-GENERATED METHOD STUB
}
}
At the time of the if_refresh
, the data starts to be updated constantly, contrary to the installed new parameters. I ask the advice – how to correctly implement the change in the parameters in locationmanager.requestlocationupdates ()
Answer 1, Authority 100%
As a result, the experienced way it turned out that should not install a movement Method to zero
lm.requestlocationupdates (locationmanager.network_provider,
120000,10, this);}
Answer 2, Authority 33%
I suspect that instead of oncreate ()
in the service you need to use onstartcommand ()
– this is the first thing noted.
And somehow strange logic: location changes – you delete the handler and put a new one with another provider. Here, too, I think it is worth changing logic.
may help – Good Way of Getting The User’s Location In Android .