How can I make a custom alertDialog close after the user activates gps? The dialog box tbm can not close while the gps condition is false, ie while it is disabled the alertDialog has to remain, but when activated the gps dialog box still remains.
Follow my code:
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
final boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!enabled) {
LayoutInflater li = getLayoutInflater();
View view = li.inflate(R.layout.alert_dialog__custom, null);
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
final AlertDialog alert = alertDialog.create();
alertDialog.setCancelable(false);
view.findViewById(R.id.btn_claro).setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
onStop();
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
});
view.findViewById(R.id.btn_depois).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
AlertSair();
}
});
alert.dismiss();
alertDialog.setView(view);
alertDialog.show();
} onResume();