0

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

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
user1120680
  • 93
  • 3
  • 14

2 Answers2

4

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.

Community
  • 1
  • 1
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
  • Thanks for responding. I believe this is what I want."What you can do is just change the layout when your screen orientation changes inside onConfigurationChanged() method," Still confused where it fits in my code? – user1120680 Apr 05 '12 at 09:50
2

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

Shankar Agarwal
  • 34,573
  • 7
  • 66
  • 64