Reputation: 5016
I have to launch the settings screen to enable location service (if it is disabled) and refresh my views after returning to my activity if the user has enabled location service.
launching settings Onclick of menu item,
startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS ), 1234);
And
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 1234 && (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER ) || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER ))){
refreshViews(); // making a server call and getting new data and assigning to views
}
}
The problem is : If i enable once and back to app its refreshing my views as i wanted. But if i click again on menu item and back to app, its refreshing again. I want to refresh my views whenever it gone to enable state from disable.
Upvotes: 0
Views: 227
Reputation: 1295
first check provider is enabled or not. if its disabled, then only start activity.
Upvotes: 1