user1120680
user1120680

Reputation: 93

Android layout configChanges

I created layout and layout-land folders, in Manifest i have

android:configChanges="keyboardHidden|orientation"

If i remove the android:configChanges from the Manifest I can see the layout change from portrait to landscape...the problem is that the previous screens are destroyed when trying to go back.

I am assuming i could add some code in my Java to tell it when to change layouts. I have read a bunch of posts already but am confused where in the code it would happen.

I am trying to use some prepackaged code because I am new to Android. The link below is the Java code for the menu screen in particular i need to change layouts for. thanks so much!!

menu Java

Upvotes: 0

Views: 4634

Answers (2)

Shankar Agarwal
Shankar Agarwal

Reputation: 34765

My work around for these problem was

in manifeast file you can use android:configChanges="keyboardHidden|orientation" if you wont these line then activity will be destroyed and created again.

and we have a below method

@Override
public void onConfigurationChanged(Configuration newConfig) {
    // TODO Auto-generated method stub
    super.onConfigurationChanged(newConfig);
    setContentView(R.layout.yourlayoutname);
}

here you can handle the orientation change...

Upvotes: 2

Lalit Poptani
Lalit Poptani

Reputation: 67286

Adding android:configChanges="keyboardHidden|orientation" will stop re-creation of your Activity and also prevent from changing the layout to layout-land/portrait layout. In that case you have to manage it manually from the java code. If you don't want your Activity to get re-created when you rotate your device/ change orientation. What you can do is just change the layout when your screen orientation changes inside onConfigurationChanged() method,

Check my answer here, how can that be done.

Upvotes: 4

Related Questions