show currently visible fragment in orientation change gives empty/null view android
<p>Good day all, I am kind of stuck on something and i think i am mistakening a concept in the way fragments and activities are handled during an orientation change. Basically, i have 3 fragments in an activity, loaded dynamically through framelayout via footers. By default, when the app is started, the first fragment is shown, which means that anytime the activity is destroyed and created, the first fragment is shown. now what i want is the current visible fragment before an orientation change to be visible after an orientation change with a different UI layout. but i get a Null views when i try showing the fragment or any other.</p>

<p>in my Activity onCreate i have this:</p>

<pre><code>if(savedInstanceState != null){
            switchTag = savedInstanceState.getString(SAVED_CURRENT_FRAGMENT_STATE);
            Log.d(TAG, "fragment after orientation is " + switchTag);   
              displayCurrentFragment(switchTag);        

        }else {

             dashboardfragment = new DashBoardFragment();
              ft.add(R.id.dashboard_fragment_container_id, dashboardfragment, DASHBOARD_FRAG_TAG);
              ft.commit();
        }       
</code></pre>

<p>and i override onSaveInstanceState and onConfigurationChanged in the activity:</p>

<pre><code>@Override
public void onSaveInstanceState(Bundle outState) {

    Log.d(TAG, "OnSavedInstance() on dashboard activity");
    outState.putString(SAVED_CURRENT_FRAGMENT_STATE, switchTag);  // to save the current visible fragment

    super.onSaveInstanceState(outState);

}

@Override
public void onConfigurationChanged(Configuration newConfig) {
  super.onConfigurationChanged(newConfig);
  setContentView(R.layout.dashboard_layout);  // same as oncreate
}
</code></pre>

<p>i also override the OnsaveInstanceState() in the fragments as well.</p>

<p>So my question</p>

<ol>
<li><p>is this the right way to handle fragments and activity in screen orientation?</p></li>
<li><p>if i override onsavedInstanceState in my fragments, what particular method gets called up in the activity? </p></li>
</ol>

<p>am sorry if my question is all over the place, but it's getting me really confused! what is the actual process of holding fragment state in orientation change. Thank you.</p>
