I was testing the behavior of AlertDialog to integrate in a bigger component. I am unable to show the same dialog again. Here is the test code:
public class MainActivity extends AppCompatActivity {
private AlertDialog alertDialogACCreationRetry;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
alertDialogACCreationRetry = new AlertDialog.Builder(this)
.setTitle("Account creation failed")
.setMessage("There was a problem connecting to the Network. Check your connection.")
.setPositiveButton("Retry", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).create();
alertDialogACCreationRetry.show();
alertDialogACCreationRetry.show();
}
}
I have tried putting the alertDialogACCreationRetry.show();
inside the Retry button but it still won't show. I have also tried putting alertDialogACCreationRetry.dismiss();
inside the Retry button and then calling alertDialogACCreationRetry.show();
outside, it still doesn't show. More so it is frightening that it doesn't give me an exception on reshowing it if that is not supposed to be allowed.
So, my question is this: Will I have to create a new Dialog every time after once it is dismissed(automatically) on pressing a button?