In my application the user must have at least one location provider enabled. In order to know if one is enabled I use:
isGpsLocationEnabled = ((LocationManager) getSystemService(LOCATION_SERVICE))
.isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetworkLocationEnabled = ((LocationManager) getSystemService(LOCATION_SERVICE))
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Now, I created an Activity alerting that none is enabled and if the user selects “Enable GPS” I open the gps options with ACTION_LOCATION_SOURCE_SETTINGS intent.
I want (After the selection of the user) to check if he enabled one, and only let him continue if he did.
I have this code in the button “Enable GPS”
showGpsOptions();
isGpsLocationEnabled = ((LocationManager) getSystemService(LOCATION_SERVICE))
.isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetworkLocationEnabled = ((LocationManager) getSystemService(LOCATION_SERVICE))
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (isGpsLocationEnabled || isNetworkLocationEnabled){
Intent startIntent = new Intent(EnableLocationProviderActivity.this, SensingService.class);
startService(startIntent);
} else {
finish();
}
My problem is that isGpsLocationEnabled and isNetworkLocationEnabled never gets updated with the user selection in the network settings as the code continues its execution after showGpsOptions() (I know it can’t block the UI thread, but how can I overpass this situation)??
Is there anyway to execute code after the user selects something in the network settings?
Thanks! Guillermo.
when settings screen come in front of your
activity, logically and acc to docs, youractivityispausedand then when it is required youractivityisresumed… so i guess, you should use the checking code inonResume…