-4

My application having landscape and portrait mode. so I designed two layouts for each mode. In manifest file I set the below code.

android:configChanges="orientation"

it's working fine but the activity restarts on every orientation changes. so I add the following line to avoid the recreate issue.

android:configChanges="keyboardHidden|orientation|screenSize"

Now the activity is not recreating but it also not taking the landscape mode design.

please help me to solve this issue friends

user1517638
  • 972
  • 1
  • 10
  • 16
  • The activity recreation is intended to redraw with the proper layout, if you disable it, it will now draw your landscape layout. – Nanoc Nov 23 '15 at 14:41
  • You should check this: http://stackoverflow.com/a/8093902/3743245 is older than Jesus – Mariano Zorrilla Nov 23 '15 at 14:44
  • That's how orientation works: by recreating the Activity. If you disable it... you lose it. It appears quite obvious. Or isn't it? – Phantômaxx Nov 23 '15 at 15:09

2 Answers2

2

I would recommend letting the Application recreate itself on orientation change.

If you need to preserve state then store information when onSaveInstanceState is called.

/**
 * On min or rotate save state info.
 *
 * @param bundle saved values
 */
public void onSaveInstanceState(Bundle bundle) {

    bundle.putBoolean("SomeKey", someKeyValue);
    super.onSaveInstanceState(bundle);
}

and then recover the values in onCreate

    if (savedInstanceState != null) {

        if (savedInstanceState.containsKey("SomeKey")) {
            someKeyValue=  
               savedInstanceState.getBoolean("SomeKey");
        }

    }

Using onConfigChanges: is a slippery slope that works well until it doesn't. Behavior varies and gets more complex with each OS release.

mjstam
  • 1,049
  • 1
  • 6
  • 5
0

In my case my app work fine in both orientation here is what i doing may it help you,

use same code in public void onCreate(Bundle savedInstanceState) { // your code } and public void onConfigurationChanged(Configuration newConfig) { // your code }

and in AndroidManifest file

use like

 <activity
        android:name="YourActivity"
        android:configChanges="orientation|screenSize"
        android:windowSoftInputMode="stateHidden" />

that's it. if any issue post your comment

Arpan24x7
  • 648
  • 5
  • 24