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

  • SEARCH
  • Home
  • 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 7185571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:26:43+00:00 2026-05-28T18:26:43+00:00

When I change device orientation, if AlertDialog was shown, it disappears. This is true

  • 0

When I change device orientation, if AlertDialog was shown, it disappears. This is true for all but one dialogs in my app, and I can’t figure out neither what’s so special about the one that doesn’t disappear nor how to counteract this behaviour. Any possibility to preserve dialogs upon orientation change (except for manual management)?

  • 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-05-28T18:26:44+00:00Added an answer on May 28, 2026 at 6:26 pm

    As suggested by many people here,

    android:configChanges="keyboardHidden|orientation"
    

    is not a solution. It’s a hack at best. The correct way to handle this is to manage dialogs through your activity. You need to override a few methods in your activity code, Like so:

    protected Dialog onCreateDialog(int id) {
        // create and return your dialog instance here
        AlertDialog dialog = new AlertDialog.Builder(context)
            .setTitle(title)
            .setIcon(R.drawable.indicator_input_error)
            .setMessage(message)
            .create();
        dialog.setButton(
                DialogInterface.BUTTON_POSITIVE,    
                context.getString(R.string.OK),
                (DialogInterface.OnClickListener) null);
        return dialog;
    }
    
    protected void onPrepareDialog(int id, Dialog dialog) {
        // You dialog initialization code here
    }
    

    After you’re done with this. You show your dialog using:

    showDialog(yourDialogID);
    

    Once you’re done implementing this, your’ll see that your dialog will also be recreated if configuration changes occur. The best part is that your Activity will manage your dialog for you. It will be reused when possible, reducing dialog load times if you perform heavy initialization.

    Note from Android SDK documentation:
    Using this attribute should be avoided and used only as a last-resort. Please read Handling Runtime Changes for more information about how to properly handle a restart due to a configuration change.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know how to detect device orientation change on iOS in Safari, but I
Here is my Layout.But when I change the device orientation,although I am using dp
I would like to handle the orientation change of my app with a menu
I have this bit of jQuery: $('body').bind('orientationchange',function(event){ alert('orientationchange'); }) If you change the orientation
I'm developing an application in android 2.2. When change the device orientation (by rotate
How can I programmatically check whether the device orientation is locked in iOS? I
Why the uiview changes orientation automatically when change the device orientation and not completely
I'm using the following code to detect/listen for when the iPad changes device orientation.
I am using the XML tag android:configChanges=orientation|keyboardHidden|keyboard and the following code to detect device
I have posted my question to developer.appcelerator.com. http://developer.appcelerator.com/question/124915/device-orientation-does-not-reflect-scrollview-content-resizing ======================================================================= I have scrollview resize problem

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.