Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8561739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:34:13+00:00 2026-06-11T16:34:13+00:00

I have an activity(ImportActivity) ,where user inputs some values for a measure and save

  • 0

I have an activity(ImportActivity) ,where user inputs some values for a measure and save them into a sqlite database.

When the user clicks save button after import to the database i have an alert dialog(SAVEORBACK_DIALOG_ID),where the user can leave this activity or import another measure.It works perfect.

My problem is when i try to show another alert dialog(SMS_DIALOG_ID) just before (SAVEORBACK_DIALOG_ID) alert dialog.This because i want to ask the user to send or not an sms.

When i run this it shows me only the second alert dialog(SAVEORBACK_DIALOG_ID)!!

ImportActivity
this is final dialog

I have in the activity:

static final int DATE_DIALOG_ID = 0;
static final int TIME_DIALOG_ID = 1;
static final int SAVEORBACK_DIALOG_ID = 2;
static final int SMS_DIALOG_ID = 3;

I call them from my activity :

// sms dialog (send sms to doctor? yes/no)
showDialog(SMS_DIALOG_ID);

// save or back dialog
showDialog(SAVEORBACK_DIALOG_ID);

Here is the onCreateDialog method where I have my dialogs(I removed some to be easier to read):

    @Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DATE_DIALOG_ID:
        return new DatePickerDialog(this, mDateSetListener, mYear, mMonth,
                mDay);
    case TIME_DIALOG_ID:
        return new TimePickerDialog(this, mTimeSetListener, mHour, mMinute,
                false);
    case SAVEORBACK_DIALOG_ID:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(
                "Information saved successfully ! Add Another Info?")
                .setCancelable(false)
                .setPositiveButton("No",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                                ImportActivity.this.finish();

                            }
                        })
                .setNegativeButton("Yes",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                                dialog.cancel();
                                // get the new date
                                // Clearing the fields & update date/time
                                // textviews
                            }
                        });
        AlertDialog dialog = builder.create();
        return dialog;

        // case sms dialog
    case SMS_DIALOG_ID:
        AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
        builder2.setMessage("High blood pressure ! Send sms to doctor?")
                .setCancelable(false)
                .setPositiveButton("No",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                                dialog.cancel();
                                // do nothing - just continue
                            }
                        })
                .setNegativeButton("Yes",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                                dialog.cancel();
                                // try to send sms - report status
                            }
                        });
        AlertDialog dialog2 = builder2.create();
        return dialog2;
        //

    }
    return null;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:34:14+00:00Added an answer on June 11, 2026 at 4:34 pm

    These commands are executed consecutively, which as you noticed, overwrites the first dialog:

        // sms dialog(send sms to doctor?yes/no)
        showDialog(SMS_DIALOG_ID);
    
        // save or back dialog
        showDialog(SAVEORBACK_DIALOG_ID);
    

    because showDialog() does not wait for a response from the first dialog before displaying the second.

    Simply move your second showDialog() command to the Buttons in your first dialog:

    .setPositiveButton("No",
        new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
                // do nothing - just continue
                ImportActivity.this.showDialog(SAVEORBACK_DIALOG_ID);
            }
        })
    // etc, etc
    

    Alternatively you can use an OnDismissDialogListener, this is called whenever the dialog is closed (via a Button click, cancel action, etc.):

    case SMS_DIALOG_ID:
        ...
        AlertDialog dialog2 = builder2.create();
    
        dialog2.setOnDismissListener(new OnDismissListener() {
            public void onDismiss(DialogInterface dialog) {
                ImportActivity.this.showDialog(SAVEORBACK_DIALOG_ID);
            }
        });
    
        return dialog2;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have activity A with a listView, a user clicks on any item which
I Have activity that get some data from the internet, and shows it to
I have Activity with some data displayed in WebView that I load with WebView#loadDataWithBaseURL
I have an activity that starts on demand of the user. The user can
I have an Activity with ListView took in my Database. I would like to,
I have activity that load's image from server into imageview. Image is displayed after
i have a activity which extends ListActivity. The Layout contains some generic widget an
I have an activity in which some of the TextViews are empty at the
I have an activity which has some text views and other data to be
I have Activity with ListView and buttons - clear all and OK. On button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.