Max Zavernutiy
Max Zavernutiy

Reputation: 1869

Activity does not restart after orientation change

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">

Upvotes: 0

Views: 84

Answers (1)

Miki Franko
Miki Franko

Reputation: 687

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>

Upvotes: 2

Related Questions