I have a trouble with AlertDialog
. If i will call dialog.show()
after dialog.hide()
it will not be shown, but if I call dialog.show()
again, all ok. If i call dialog.show()
twice in a row, dialog showing always.
And If replace hide() -> dismiss()
it is ok allways. But in my case i need to use hide()
to save the dialog.
SAMPLE
AlertDialog dialog;
@Override
protected void onCreate(@Nullable Bundle savedState) {
super.onCreate(savedState);
setContentView(R.layout.activity_auth);
dialog = new AlertDialog.Builder(this)
.setTitle("Title")
.setMessage("Text")
.setPositiveButton("Yes", (dialogInterface, which) -> onYesClicked())
.create();
Button login = findViewById(R.id.btn_login);
login.setOnClickListener(v -> dialog.show());
}
private void onYesClicked() {
dialog.hide();
}
EDITED: SOLUTION
private void onYesClicked() {
new Handler().post(() -> dialog.hide());
}