Search code examples
android-fragmentsscreen-orientation

Change Orientation with different layout (Out of memory)


My app have two different layouts, one for portrait and another for landscape. I define two .xml with the same name but change some position of view. All things work perfectly until I change the orientation. When I change the orientation I get "out of memory". I use a class that extend of "FragmentStatePageAdapter" where I create fragments. I override "onConfigurationChange", like this:.

setContentView(R.layout.main); //If I don't use this, the views not change
fragmentStatePagerAdapter = new FragmentStatePagerAdapterPersonal(fragmentManager);
viewPager.setAdapter(fragmentStatePagerAdapter);
fragmentStatePagerAdapter.notifyDataSetChange();

Solution

  • I solved the problem adding the next line to remove out of memory in "onConfigurationChange"

    viewPager.setAdapter(null);
    fragmentStatePagerAdapter.notifaDataSetChanged();