0

I'm having a problem with my Android project. I'm creating different layouts for phone and tablet, but having some issues. These layouts use different fragments. This is my MainActivity onCreate method:

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation);

    if (isTablet(this.getApplicationContext()) &&
            getResources().getConfiguration().orientation
            == Configuration.ORIENTATION_LANDSCAPE){
        mNavigationFragment = (NavigationFragment)
                getSupportFragmentManager().findFragmentById(R.id.navigation);

    } else {
        mNavigationDrawerFragment = (NavigationDrawerFragment)
                getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
        // Set up the drawer.
        mNavigationDrawerFragment.setUp(
                R.id.navigation_drawer,
                (DrawerLayout) findViewById(R.id.drawer_layout));

    }

    mTitle = getTitle();

    getSupportFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {

        @Override
        public void onBackStackChanged() {
            Fragment f = getSupportFragmentManager().findFragmentById(R.id.container);
            if (f != null){
                updateTitleAndDrawer (f);
            }

        }
    });
}

And this is isTablet method:

public static boolean isTablet(Context context) {
    return (context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK)
            >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

But the point is, when I change the orientation the layout does not change. Can you please tell some advices?

Forgot to mention, I have the following line in AndroidManifest

android:configChanges="keyboardHidden|orientation|screenSize">
Max Zavernutiy
  • 1,771
  • 1
  • 18
  • 27

1 Answers1

2

you should add to your mainActivity:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

}

and add to your manifiest:

<activity
    android:configChanges="orientation"
</activity>
Miki Franko
  • 687
  • 3
  • 7
  • Sorry, i forgot to mention that i have the followin line in manifest android:configChanges="keyboardHidden|orientation|screenSize" And it still doesn't work with your advice – Max Zavernutiy Feb 05 '15 at 13:43
  • 1
    Actually I added to the onConfigurationChanged finish(); startActivity(getIntent()); and now the activity is restarting – Max Zavernutiy Feb 05 '15 at 15:06