else{ //this is part of some onclick listener of a button in the program
slider.close();
mapView.setClickable(false);
Toast.makeText(getBaseContext(), "GPS cannot retrieve your location. GPS needs clear sky or service is off. Please turn on GPS service.", Toast.LENGTH_LONG).show();
final Button bt = (Button)findViewById(R.id.turnGPS);
bt.setVisibility(View.VISIBLE);
bt.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
Intent activateGps = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
//Map.this.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
Map.this.startActivityForResult(activateGps, RESULT_OK);
//bt.setVisibility(View.INVISIBLE);
return false;
}
});
}
}
I want to start new intent so user can enable GPS (if GPS is not activated before). I used startActivityForResult method that can respond whether Activity has resulted success or not. When success it has to do some changes on the user interface....I tried and I enable the GPS but still no changes on the UI (e.g: button does not hide). What I'm doing wrong?
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode==RESULT_OK)
{
if(resultCode == RESULT_OK && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
{
Button bt = (Button)findViewById(R.id.turnGPS);
bt.setVisibility(View.INVISIBLE);
this.finish();
}
else if(resultCode == RESULT_CANCELED)
{
Toast.makeText(getBaseContext(), "No GPS device or service enabled", Toast.LENGTH_LONG+Toast.LENGTH_LONG).show();
}
}
super.onActivityResult(requestCode, resultCode, data);
}
Here is my onActivityResult method. Does this.finish(); finishes the current activity when it is enabled, so it initiates OnResume()?