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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:24:19+00:00 2026-06-08T15:24:19+00:00

I get this error whenever I have my main activity with a fragment loaded

  • 0

I get this error whenever I have my main activity with a fragment loaded and the user starts a new activity, switches the orientation of the device and comes back to main activity.

@Override
public void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.home_layout);
    super.onCreate(savedInstanceState);
    fragmentManager = getSupportFragmentManager();
    fragment = fragmentManager.findFragmentById(R.id.layFragment);

    initialize();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    setContentView(R.layout.home_layout);
    initialize();
    super.onConfigurationChanged(newConfig);
}

private void initialize() {
    layStatus = (LinearLayout) findViewById(R.id.layStatus);
    txtStatus = (TextView) findViewById(R.id.txtStatus);
    ....
    handleFragments(lastFragmentId);
}

public void handleFragments(int fragmentId) {
        if (fragment == null) {
            FragmentTransaction ft = fragmentManager.beginTransaction();
            if (fragmentId==someFragmentId){
                ft.replace(R.id.layFragment, new FragmentSomeFragment());
            }
            else
            ....

            ft.commit();
        }
}

In my android manifest, the activity is declared as:

 <activity
        android:name=".HomeActivity"
        android:configChanges="keyboardHidden|orientation" />
<activity

In another questions here on SO, I have found that this may be caused by a bug in Support library do I added without any luck:

// needed as a workaround for a bug in the Support library
@Override
protected void onSaveInstanceState(Bundle outState) {
    outState.putString("WORKAROUND_FOR_BUG_19917_KEY", "WORKAROUND_FOR_BUG_19917_VALUE");
    super.onSaveInstanceState(outState);
}

My app runs from android 2.2 and I’m using the android-support-v4.jar Support library for fragments.

The log looks like:

07-27 11:56:20.399: E/AndroidRuntime(16021): FATAL EXCEPTION: main
07-27 11:56:20.399: E/AndroidRuntime(16021): java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
07-27 11:56:20.399: E/AndroidRuntime(16021):    at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1299)
07-27 11:56:20.399: E/AndroidRuntime(16021):    at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1310)
07-27 11:56:20.399: E/AndroidRuntime(16021):    at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:541)
07-27 11:56:20.399: E/AndroidRuntime(16021):    at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:525)
07-27 11:56:20.399: E/AndroidRuntime(16021):    at com.rightcab.driver.core.HomeActivity.handleFragments(HomeActivity.java:341)
07-27 11:56:20.399: E/AndroidRuntime(16021):    at com.rightcab.driver.core.HomeActivity.initialize(HomeActivity.java:128)
07-27 11:56:20.399: E/AndroidRuntime(16021):    at com.rightcab.driver.core.HomeActivity.onConfigurationChanged(HomeActivity.java:153)
07-27 11:56:20.399: E/AndroidRuntime(16021):    at android.app.ActivityThread.performConfigurationChanged(ActivityThread.java:3618)
07-27 11:56:20.399: E/AndroidRuntime(16021):    at android.app.ActivityThread.handleActivityConfigurationChanged(ActivityThread.java:3771)
07-27 11:56:20.399: E/AndroidRuntime(16021):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1328)
07-27 11:56:20.399: E/AndroidRuntime(16021):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-27 11:56:20.399: E/AndroidRuntime(16021):    at android.os.Looper.loop(Looper.java:137)
07-27 11:56:20.399: E/AndroidRuntime(16021):    at android.app.ActivityThread.main(ActivityThread.java:4745)
07-27 11:56:20.399: E/AndroidRuntime(16021):    at java.lang.reflect.Method.invokeNative(Native Method)
07-27 11:56:20.399: E/AndroidRuntime(16021):    at java.lang.reflect.Method.invoke(Method.java:511)
07-27 11:56:20.399: E/AndroidRuntime(16021):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
07-27 11:56:20.399: E/AndroidRuntime(16021):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
07-27 11:56:20.399: E/AndroidRuntime(16021):    at dalvik.system.NativeStart.main(Native Method)
  • 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-08T15:24:20+00:00Added an answer on June 8, 2026 at 3:24 pm

    First, as I can see, you want to handle configuration changes yourself. In order to let things to work properly with API Level 13+, you have to add one more value to configChanges parameter, as described here.

    Next, when the user leave your main activity, onSaveInstanceState and onPause methods are called for it. When the user rotates device and come back to your main activity. onConfigurationChanged method is called before onResume(). So, your activity is still paused and you cannot perform FragmentTransaction.

    Further more, if we take a look into source code we can see the following comment for onResume method:

    Dispatch onResume() to fragments. Note that for better
    inter-operation with older versions of the platform, at the point of
    this call the fragments attached to the activity are not
    resumed. This means that in some cases the previous state may still
    be saved, not allowing fragment transactions that modify the state.
    To correctly interact with fragments in their proper state, you should
    instead override {@link #onResumeFragments()}.

    So, the right place to manipulate fragments in your activity is overriding onResumeFragments method, as we can read in the comment for this method in source code:

    This is the fragment-orientated version of {@link #onResume()} that
    you can override to perform operations in the Activity at the same
    point where its fragments are resumed. Be sure to always call through
    to the super-class.

    protected void onResumeFragments() {
        super.onResumeFragments();
    
        // YOUR STUFF IS HERE
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whenever I try installing anything using gem, I get this error - murtaza@murtaza-dev:~$ sudo
whenever I try to call my ejb from a client, I get this error
I get this error on my Ice Cream Sandwich (Android 4.0) device and emulator.
I get this error when I run the code below. I have normally used
Whenever I require a file in ruby or irb I get this error: LoadError:
I get this error while accessing a php script: W/System.err: Error reading from ./org/apache/harmony/awt/www/content/text/html.class
I get this error when i try to upload an image: OSError at /upload/
I get this error when I use simplejson from django.utils in google app engine
I get this error in my app { error: { message: Missing client_id parameter.,
i get this error Cannot open database DataLayer.Context.MedicallexiconContext requested by the login. The login

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.