ActionBar Tabs with fragments on rotate

I’am build an app with an ActionBar and two Tabs below.
Everything works fine if the device / emulator isnt rotated. If rotated, tab state switches automaticale to tab1 (normal, because onCreate get called) but the content dont get changed. If I select a tab in the new orientation, the onCreateView() method from the selected Fragment get called but the view dont get updated (stay always the same). Any Tips?

The code.

  • Recyclerview and handling different type of row inflation
  • Add a GridView to a ListView in Android
  • No Default Proposals in Eclipse Juno
  • How to play ringtone/alarm sound in Android
  • Using DiskLruCache in android 4.0 does not provide for openCache method
  • How to set image in imageview in android?
  • Main Activity:

        ActionBar actionbar = getActionBar();
        ActionBar.Tab ATab = actionbar.newTab().setText(R.string.player);
        ActionBar.Tab BTab = actionbar.newTab().setText(R.string.stations);
        Fragment AFragment = new AFragment();
        Fragment BFragment = new BFragment();
        PlayerTab.setTabListener(new MyTabsListener(AFragment));
        StationsTab.setTabListener(new MyTabsListener(BFragment));

    With identical tabs that display a simple textview. The textview simple say which tab is selected.


    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.a, container, false);

    The Fragment layout, mentioned above, only contains a TextView with hardcoded Text. (Only for testing purposes)

    The Main layout looks like this.

    <?xml version="1.0" encoding="utf-8"?>
    android:layout_height="fill_parent" >
            android:layout_height="match_parent" >

    Related posts:

    Android : References to a Context and memory leaks
    Possible to override/apply style in layout included with &lt;include&gt; tag?
    Android: download large file
    Android: How can I set a listener to the MenuButton?
    Add productFlavor to experimental Android gradle plugin library
    SVG image not visible in android 3.0+ with same code
  • Is it possible to use something other than a listview as sliding drawer in drawerlayout
  • Monkey made my app meow
  • Android support library increases APK size a lot
  • Android EditText Hint
  • How do I clear up this ambiguous call to Arrays.copyof()?
  • Android - how to unregister a receiver created in the manifest?
  • One Solution collect form web for “ActionBar Tabs with fragments on rotate”

    Solved. I have recreated the fragment everytime, doesnt do that anymore solved it.

    Changed in my TabListener and onTabSelected(Tab tab, FragmentTransaction ft), ft.add() to ft.replace()

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.