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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:56:00+00:00 2026-05-27T11:56:00+00:00

After the Fragments API being released, I started porting all my deprecated dialogs into

  • 0

After the Fragments API being released, I started porting all my deprecated dialogs into DialogFraments using the compatibility package. Everything was working well, until I notice that my dialogs are causing crashes to ICS only:

E/AndroidRuntime(  883): FATAL EXCEPTION: main
E/AndroidRuntime(  883): java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
E/AndroidRuntime(  883):    at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1254)
E/AndroidRuntime(  883):    at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1265)
E/AndroidRuntime(  883):    at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:541)
E/AndroidRuntime(  883):    at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:525)
E/AndroidRuntime(  883):    at android.support.v4.app.DialogFragment.show(DialogFragment.java:123)
E/AndroidRuntime(  883):    at com.myapp.ui.dialogs.TwoButtonDialogFragment.showDialog(TwoButtonDialogFragment.java:84)

My dialogs are shown on AsyncTask.onPostExecute() in order to show an http response to the user. After diving into the problem, I got the conclusion that this exception only happens when the Activity is paused or stopped, and it does not happen on other versions of Android.
I’ve tried using commitAllowingStateLoss(), but it doesn’t help, since the exception is thrown on DialogFragment.show(). Here’s my code for the DialogFragment:

private static void showDialog(FragmentActivity activity, String title, String msg, 
        String positiveButtonText, String negativeButtonText, int id, Bundle args) {

    if (activity.isFinishing()) {
        return;
    }

    FragmentManager fmgr = activity.getSupportFragmentManager();
    FragmentTransaction ft = fmgr.beginTransaction();
    Fragment prev = fmgr.findFragmentByTag(TAG);
    if (prev != null) {
        try {
            ft.remove(prev);
        } catch (IllegalStateException ex) {
            // issue: http://code.google.com/p/android/issues/detail?id=17029
        }
    }

    TwoButtonDialogFragment newFragment = new TwoButtonDialogFragment();
    if (args == null) {
        args = new Bundle();
    }
    args.putString("title", title);
    args.putString("message", msg);
    args.putString("positiveButtonText", positiveButtonText);
    args.putString("negativeButtonText", negativeButtonText);
    args.putInt("id", id);
    newFragment.setArguments(args);
    newFragment.setCancelable(false);
    newFragment.show(fmgr, TAG); // exception is thrown here
    ft.commit();
}


@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Bundle args = getArguments();
    String title = args.getString("title");
    String msg = args.getString("message");
    String positiveButtonText = args.getString("positiveButtonText");
    String negativeButtonText = args.getString("negativeButtonText");
    final int id = args.getInt("id");

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    if (!TextUtils.isEmpty(title)) {
        builder.setTitle(title);
    }
    builder.setMessage(msg);

    final TwoButtonDialogHandler handler = (TwoButtonDialogHandler) getActivity();
    builder.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {              
            handler.doPositiveClick(id, args);
        }
    });
    builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            handler.doNegativeClick(id, args);
        }
    });

    return builder.create();
}

Is it a bug on ICS? What am I supposed to do?

  • 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-27T11:56:00+00:00Added an answer on May 27, 2026 at 11:56 am

    I encountered this problem and could find no way in the framework to address this issue.

    However I did provide a workaround to the problem which you can see at the following link

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

Sidebar

Related Questions

Using the compatibility package to target 2.2 using Fragments. After recoding an activity to
I'm using the compatibility package v4 in my project and I'm having an issue
After reading the Head First Design Patterns book and using a number of other
After being told by at least 10 people on SO that version control was
I have an activity(say, MyActivity) that contains fragments, and i am using fragmentTransaction.replace(XX,YY) for
What a question! To describe it more clearly: I'm using fragments and my target
I have a text file which all contain the following fragments of code in
After hearing about OSGi fragments, I was wondering: Can I use a fragment to
yesterday I noticed the possibility to integrate Fragments in older API Levels through the
I recently converted my Activities to Fragments. Using something similar to Tab-Navigation the fragments

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.