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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:49:20+00:00 2026-06-18T00:49:20+00:00

i have a problem with fragments and rotating screen. I read this threads, and

  • 0

i have a problem with fragments and rotating screen. I read this threads, and it didn’t solve my problem:

Fragment without a view crashes on configuration change (isn’t exactly the same)

IllegalStateException when replacing a Fragment (not solve my problem)

I have only one activity:

public class MainActivity extends FragmentActivity implements TabSelectedListener {

    /** Application tab menu */
    private TopMenu menu;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        menu = (TopMenu) this.findViewById(R.id.menu);
        menu.setListener(this);


    }//onCreate

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        // TODO Auto-generated method stub
        super.onSaveInstanceState(outState);
    }

    public void tabSelected(int tab) {

        FragmentManager fragmentManager = this.getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        Fragment f = null;

        boolean logged = DataController.getInstance().getLogged();

        switch(tab){
        case TopMenu.TAB1:
            if( !logged ){
                f = new HomeFragment();
            }else{
                f = new AccountsFragment();
            }
            break;
        case TopMenu.TAB2:
                     // i create more fragments depending the tab
        }   

        if( f != null){

            // Replace whatever is in the fragment view with this fragment,
            // and add the transaction to the back stack
            fragmentTransaction.replace(R.id.fragment, f);
            fragmentTransaction.addToBackStack(null);

            // Commit the transaction
            fragmentTransaction.commit();
        }

    }//tabSelected

    public void setSelectedTab(int tab){
        menu.setSelectedTab(tab);
    }


 .....
}

And the code of the fragment is:

public class HomeFragment extends Fragment implements OnClickListener{

    private static final String KEY_STATE_BUNDLE = "HomeFragmentManagerState";

    private LocalActivityManager mLocalActivityManager;

    View homeRelative;
    View homeLocked;
    View homeUnlocked;

    EditText id;
    Button ok;
    ImageView lock;
    CheckBox remember;

    private boolean lock_state;



    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            Bundle state = null;
            if (savedInstanceState != null) {
                state = savedInstanceState.getBundle(KEY_STATE_BUNDLE);
                lock_state=savedInstanceState.getBoolean("lock_state");
            } else {
                lock_state=true;
            }

            mLocalActivityManager = new LocalActivityManager(getActivity(), true);
            mLocalActivityManager.dispatchCreate(state);
        }  


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_home, container, false);

        homeRelative = view.findViewById(R.id.home_relative);
        homeLocked = view.findViewById(R.id.ly_home_buttonlogin);
        homeLocked.setOnClickListener(this);

        homeUnlocked = view.findViewById(R.id.ly_home_buttonlogin_unlocked);
        id = (EditText) view.findViewById(R.id.userid);

        ok = (Button) view.findViewById(R.id.useridok);
        ok.setEnabled(false); // ?? if id.equalsIgnoreCase("")
        ok.setOnClickListener(this);
        lock = (ImageView) view.findViewById(R.id.iv_home_candado);
        lock.setOnClickListener(this);

        if (!lock_state)
            animateLogon(true);

        remember = (CheckBox) view.findViewById(R.id.remember);

        id.addTextChangedListener(new TextWatcher(){
            public void afterTextChanged(Editable s) {

                ok.setEnabled(!id.getText().toString().equalsIgnoreCase(""));

                id.setBackgroundResource(R.drawable.bordercolorblack_rightsquare);
            }
            public void beforeTextChanged(CharSequence s, int start, int count, int after){}
            public void onTextChanged(CharSequence s, int start, int before, int count){}
        }); 

        return view; 

    }

….

And only when I change the tab, and after I rotate my device, I get one FC and the logcat is this:

10-01 14:04:07.561: E/AndroidRuntime(11759): FATAL EXCEPTION: main
10-01 14:04:07.561: E/AndroidRuntime(11759): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.stkaction.sov/com.stkaction.sov.MainActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class fragment
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3362)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.app.ActivityThread.access$700(ActivityThread.java:127)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1162)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.os.Looper.loop(Looper.java:137)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.app.ActivityThread.main(ActivityThread.java:4511)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at java.lang.reflect.Method.invokeNative(Native Method)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at java.lang.reflect.Method.invoke(Method.java:511)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:986)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:753)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at dalvik.system.NativeStart.main(Native Method)
10-01 14:04:07.561: E/AndroidRuntime(11759): Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class fragment
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:272)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.app.Activity.setContentView(Activity.java:1835)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at com.stkaction.sov.MainActivity.onCreate(MainActivity.java:29)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.app.Activity.performCreate(Activity.java:4470)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
10-01 14:04:07.561: E/AndroidRuntime(11759):    ... 12 more
10-01 14:04:07.561: E/AndroidRuntime(11759): Caused by: java.lang.IllegalStateException: Fragment com.com.stkaction.sov.HomeFragment did not create a view.
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:293)
10-01 14:04:07.561: E/AndroidRuntime(11759):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
10-01 14:04:07.561: E/AndroidRuntime(11759):    ... 22 more

Thanks to all.

  • 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-18T00:49:22+00:00Added an answer on June 18, 2026 at 12:49 am

    I found the solution. When you use dynamic fragments, you must use a layout, and put the fragment inside it.

    For example:
    The main activity use this layout:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" 
        android:id="@+id/activity_main_layout">
    
        <com.myproyect.TopMenu
            android:id="@+id/menu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
        />
    
        <!-- this was the problem
        <fragment 
            android:id="@+id/fragment"
            android:layout_width="match_parent" 
            android:layout_height="match_parent"
            class="com.myproyect.HomeFragment"
            android:layout_below="@id/menu"
        />  -->
    
        <FrameLayout android:id="@+id/fragment"
                android:layout_width="match_parent" android:layout_height="match_parent" 
                android:layout_below="@id/menu"/>
    
        <LinearLayout
            android:id="@+id/menu_layout"
            android:layout_width="175dp" 
            android:layout_height="wrap_content"
            android:background="@drawable/menu_filtros" 
            android:layout_marginRight="5dp"
            android:layout_below="@id/menu"
            android:layout_marginTop="-47dp"
            android:layout_alignParentRight="true"
            android:visibility="gone"
            android:orientation="vertical">
        </LinearLayout>
    </RelativeLayout>
    

    And I instantiate the fragment inside the FrameLayout.

    fragmentTransaction.replace(R.id.fragment, f);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I encountered this annoying problem, where I have 2 fragments, and I am running
I'm using ActionBarSherlock and have a little problem. In the Fragment Tabs example, there
I have problem with my query on C, I’m using the oci8 driver. This
I have two fragments: 1st fragment consists of a large button in the middle
I have a problem with referencing my Fragments inside a ViewPager. I would like
I have got a problem with android fragments. If I called the Actitiy A
I have a lot of cached fragments on my website because I use fragment
I have a problem. This code works fine on my nexus 10 android 4.2.1.
I have encountered a problem which i'm unable to solve, I googled a lot
I have application which uses fragments. Depending on screen size and orientation I'm displaying

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.