Search code examples
androidalertandroid-alertdialogperiod

Alert dialog period is to short


I have an alert dialog which is invoked when the user click back button on device but this alert is too short and the user cant read anything inside it or do any thing with it..

AlertDialog alertDialog = new AlertDialog.Builder(birthDate.this).create();
                    // Setting Dialog Title
                    alertDialog.setTitle("Alert Dialog");
                    // Setting Dialog Message
                    alertDialog.setMessage("Welcome to AndroidHive.info");
                    // Setting OK Button
                    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    // Write your code here to execute after dialog closed
                    Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_LONG).show();
                    }

I want to make the period of this alert dialog longer


Solution

  • I think you are calling alertdialog and finish() both are at same time. Try to finish the activity in the alert dialog as

    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    // Write your code here to execute after dialog closed
                    Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_LONG).show();
                    finish();// here calling finish if user click ok button.
                    }