Android alert dialog Issue

android alertdialog example
custom alertdialog android
android popup dialog example
android dialog material design
alert dialog android kotlin
alert dialog android stackoverflow
alertdialog builder android
android custom dialog with two buttons

In my android application, I use one alert dialog to display some information to the user, and if the user click the dialog , it should finish the activity. My code is

offer.this.runOnUiThread(new Runnable() {
public void run() {
    // TODO Auto-generated method stub
    AlertDialog alert=new AlertDialog.Builder(offer.this).create();
    alert.setTitle("SVSugar Mill");
    alert.setMessage("Offer Number is "+offer_no.getText().toString());
    alert.setButton("Click to Dismiss", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
        // TODO Auto-generated method stub

It doesn't wait for the user response to finish(). Instead it will be called even if the user didn't click the Alert dialog. I know this is asynchronous, but I need to do this.(The OfferNO should be displayed to the user. When the user click the alert dialog it should finish the activity). Is there any way to do this?

Someone help me


The activity will be finished without waiting for the user to click the alert dialog

public void ShowDialog(final Context context) {
        new AlertDialog.Builder(context)
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int which) {

AlertDialog, Providing configuration activities � Addressing common issues � Improve performace with hardware acceleration � Optimizing watch faces. A Dialog is small window that prompts the user to a decision or enter additional information. Some times in your application, if you wanted to ask the user about taking a decision between yes or no in response of any particular action taken by the user, by remaining in the same activity and without changing the screen, you can use Alert Dialog.

The problem is that you created two AlertDialog instances here:


Then you called dismiss() on the dialog that is not actually shown. This should fix the problem:;

Dialogs, In order to make an alert dialog, you need to make an object of AlertDialogBuilder which an inner class of AlertDialog. Its syntax is given below AlertDialog. Android AlertDialog Example. Android AlertDialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue. Android AlertDialog is composed of three regions: title, content area and action buttons. Android AlertDialog is the subclass of

use this code alert.setCancelable(false);before onClick method.

Android - Alert Dialog, seems we are able to custom the dialog's position with the backgroundInset, but I don't konw how to make it, and I am a fresher in Android� setItems – shows an array of items in the form of a list inside the alert dialog; setMultiChoiceItems – Sets a list of items to choose from inside the alert dialog; setView – Used to set a custom layout view inside the alert dialog. show() setShowListener() – This is triggered when the alert dialog is displayed on the screen.

[AlertDialog] How to position Alert Dialog properly � Issue #905 , Android Alert Dialog with RTL and Custom Font. Today I am going to write on Alert Dialog issue developers face when applying RTL to� Android AlertDialog is used in cases when we require the user to choose an option from the prompt presented on the screen. In this tutorial we will be discussing about creating different Alert Dialog with one button (OK button), two buttons (Yes and No) and three buttons (Yes, No and Cancel).

Alert Dialog with RTL & Font. Today I am going to write on Alert , Below are the steps for Creating the Alert Dialog Android Application: Step 1: Create a new project. After that, you have java and XML file. In android, Dialog is a small window that prompt messages to the user to make a decision or enter additional details. Generally, the Dialogs are used with modals event and these useful to prompt users to perform a particular action to proceed further in the application.

Android, Android AlertDialog Example with examples of Activity and Intent, Fragments, Menu, Service, alarm manager, storage, sqlite, xml, json, multimedia, speech, web� Creates an alert dialog that uses the default alert dialog theme and a custom cancel listener. AlertDialog(Context, Int32) AlertDialog(Context, Int32) Creates an alert dialog that uses an explicit theme resource. AlertDialog(IntPtr, JniHandleOwnership) AlertDialog(IntPtr, JniHandleOwnership)

  • so what is the problem here?
  • It doesn't wait for the user response to finish()
  • your question is not clear buddy.
  • So what you want is dialog appears-> wait for 5 sec-> if user press button finish activity and dont wait further or if user dont press button finish activity after 5 seconds. Is that what you want.
  • I dont need it for 5seconds, It only finish the activity when the user click the button
  • It didn't solve my issue, It doesn't wait for the user to click
  • Please remove runonUIThread from your code and simply out this. i guess your activity is closing before executing this code.
  • I run some other code, I use Progress dialog. Thats why I use runOnUIThread
  • Debug and check which thing is finishing your activity