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 9035035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:39:20+00:00 2026-06-16T08:39:20+00:00

I have a question regarding DialogFragment. I am trying to make a dialog that

  • 0

I have a question regarding DialogFragment. I am trying to make a dialog that keeps it’s state after the device is rotated. This dialog has a bunch of references to things such as adapters and other heavier objects and I need this to be kept upon rotation, if possible without having to make every reference Parcelable or Serializable in order for me to use onSaveInstanceState to save and restore them when the original activity is re-created.

I’ve noticed there’s a method called setRetainInstance(boolean) on the DialogFragment which allows you to keep the dialog fragment instance when the activity is re-created. However, when I rotate the device now, the dialog is not showing anymore. I know I can get it from the activity’s FragmentManager, but I cannot find a way to make it visible again. Any suggestions on this?

Thanks,
Mihai

  • 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-16T08:39:22+00:00Added an answer on June 16, 2026 at 8:39 am

    There are few things you need to do :

    1. use instance factory method to initiate a DialogFragment instance like this :

      public static MyDialogFragment newInstance(MyModel model) {
          MyDialogFragment myDialogFragment = new MyDialogFragment();
          Bundle bundle = new Bundle();
          bundle.putSerializable("MODEL", model);
          myDialogFragment .setArguments(bundle);
          return myDialogFragment;
      }
      
    2. by putting setRetainInstance(true) in onCreate, all of your references declared in the fragment will be kept after the original activity is re-created

      @Override
      public void onCreate(Bundle icicle) {
          this.setCancelable(true);
          setRetainInstance(true);
          super.onCreate(icicle);
      
      }
      
    3. avoiding disappear on rotation by doing this

      @Override
      public void onDestroyView() {
          if (getDialog() != null && getRetainInstance())
              getDialog().setDismissMessage(null);
          super.onDestroyView();
      

      }

    4. get your object by using

      (MyModel) getArguments().getSerializable("MODEL")
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a question regarding something which has been bugging me for some time now.I'm
I have question regarding polymorphism about its assignment statement, for Example this is The
I have a question regarding inheritance in Java. If I have this base class
I have a question regarding using intptr_t vs. long int . I've observed that
I have question regarding redirection in Grails web-flow. I am in a view state
I have a question regarding the XML Schema type. The type has to be:
I have a question regarding sorting in C#. Lets assume that there is List<Person>
I have a question regarding the php validation, I have this script $(document).ready(function(){ //
I have question regarding the particular Naive Bayse algorithm that is used in document
I would have question regarding web services. Let's say I have webservice client that

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.