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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:26:02+00:00 2026-05-27T16:26:02+00:00

Hi fellow Androiddevelopers, I try to have two DialogFragments in a row, so when

  • 0

Hi fellow Androiddevelopers,

I try to have two DialogFragments in a row, so when the first is cancelled a second one pops up.

Here is what I have so far:

In my Activity I call the following method:

void showFirstDialog() {
        // Pass the context to do a callback
        DialogFragment newFragment = ChangeDialogFragment.newInstance(mContext);
        newFragment.show(getSupportFragmentManager(), "myFirstDialogTag");
    }

In my DialogFragment I have following code to detect that it will be cancelled:

@Override
    public void onCancel(DialogInterface dialog) {
            // Use Context to do a callback and inform the Activity that
            // Fragment is cancelled
        ((Activity) mContext).firstDialogCanceled();
        super.onCancel(dialog);
    }

Back in my Activity I react on that eventy by starting the second dialog:

void firstDialogCanceled {
        DialogFragment newFragment = InformationDialogFragment.newInstance();
        newFragment.show(getSupportFragmentManager(), "mySecondDialogTag");
    }

This works perfectly as long as I don’t have an orientation change on the first dialog. When I have one I get the following error:

java.lang.IllegalStateException: Can not perform this action after
onSaveInstanceState

This exceptions is raised on the line “newFragment.show(getSupportFragmentManager(), “mySecondDialogTag”);”

What I thought how I could fix this problem is to dismiss the first dialog by hand. I tried following:

DialogFragment firstFragment = (DialogFragment) getSupportManager().findFragmentByTag("myFirstDialogTag");
firstFragment.dismiss();

Again without an orientation change everyhting is working fine. When I have an orientation change while first dialog is on screen I get a NullPointerException on line “firstFragment.dismiss()”.

Why is that happening? Why does the FragmentManager forget about my DialogFragment after a orientation change and why can’t I just show the second one. Androidreferences say:

you should use show(FragmentManager, String) or
show(FragmentTransaction, String) to add an instance of DialogFragment
to your UI, as these keep track of how DialogFragment should remove
itself when the dialog is dismissed.

I DO use show, but it is still not working properly.

Any hint is highly appreciated!

Cheers Ali3n

  • 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-27T16:26:02+00:00Added an answer on May 27, 2026 at 4:26 pm

    You are using old instance of the activity in your dialog fragment. I guess you are passing the current activity as mContext in newInstance method. After a configuration change such as orientation or keyboard, this context object becomes invalid and it is no longer attached to any window.

    You can use getActivity() method of FragmentDialog to get the current activity it lives in.

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

Sidebar

Related Questions

hello fellow java developers. I'm having a bit of an issue here. I have
Hi fellow StackOverflow guys, First of all this is on Magento 1.7.0.2. I have
Fellow Coders, so far I have been using the CI url helper to build
Fellow Stackoverflowers I have a question, since I'm not a database hero. I have
Question fellow programmers. Let's say I have a stand alone application in it's own
Hello fellow StackOverflowers. I'm have a brain fart right now, and I cannot seem
Hi fellow android developers, I'm trying to implement a multi-pane layout as described here
Fellow coders, i have a function in a codeigniter controller that accepts a couple
fellow devs! I have a class for posting to website using a POST or
Hello fellow stackies, I'm developing a site and I have a small problem. It's

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.