In my android, I want to show a message box with no way to quit it, and while its showing, another process needs to run (in my case an email sending function). Then after the email is finished sending, the alert box needs to close.
This is what i got so far, but it’s not working…
Can anyone help?
AlertDialog.Builder alertDialog = new Builder(this); // create an alert box
alertDialog.setTitle("Sending...");
alertDialog.setMessage("Please wait while your details and image is being sent to x.");
alertDialog.show(); // show the alert box
Reusable_CodeActivity.send_email(gmailAC, gmpassword, get_all_details(), image_path, this);
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { // define the 'OK' button
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
I’m not sure about the email-sending part, but I can help you make the message box like you want to.
If you remove the following code:
Then the dialog will display with no buttons, and if you add
.setCancelable(false)it will not be dismissed until you tell it to, usingalertDialog.cancel();Here’s an example (modified from one of my dialogs):
This code will display a dialog with text, which will not disappear until the activity calls
builder.dismiss();– which you’d then have to implement in some sort of a listener, or callback once the sending is complete.Update
Looking at the other answer, this is probably how your code should look like (thanks to iturki)