0

This app requires both portrait and landscape orientations. Here I am creating "layout-land" folder in resource folder for landscape orientation.While I am doing orientation activity is taking the XML from "layout-land" but activity is restarting.

So to avoid restarting,in manifest I am using the following permissions:

<android:configChanges="keyboardHidden|orientation|screenSize">

While I am using the above permissions activity is not restarting but it is unable to take the XML from "layout-land" folder.

Here I need:
1. Avoid restarting an activity
2. Making an activity to take the XML from "layout-land" folder. I am new to android.Please help me in this.Thanks in advance.

asloob
  • 1,308
  • 20
  • 34

3 Answers3

2

That's the way Android works. You need to choose one of three options:

  1. Use the exact same layout for portait and landscape; then, you can use configChanges as above. This can work even if you do have a few minor changes, if you can keep the majority of the layout the same and just make a few items visible/invisible based on orientation.

  2. Use different layouts; then, you can keep configChanges, but you have to implement loading of the new layout yourself in onConfigurationChanged, including taking all the values from the old views and adding them to the new (anything that was set at run time: text values, user entered edit texts, check box states, etc).

  3. Remove the configChange line from the manifest, and implement onSaveInstanceState and onRestoreInstanceState. These two will give you a chance to save any values you want and restore them around the restart of your activity. Basically the same as two, but you don't have to manually reset the view.

I highly suggest 1 if at all possible. If you must use a landscape specific layout, going route 3 is the easiest. I'm normally a big fan of setting configChanges, but it doesn't work well if you need a completely different landscape layout.

apaderno
  • 28,547
  • 16
  • 75
  • 90
Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
0

Try using the following.

   <uses-sdk android:targetSdkVersion="15"/>
<activity android:configChanges="orientation|screenSize|keyboardHidden" />

My activity is not restarted when switching orientation on my Galaxy Nexus running Android 4.0.4.

apaderno
  • 28,547
  • 16
  • 75
  • 90
Android
  • 106
  • 5
0

Use this one in your android menifest

android:configChanges="orientation|screenSize|keyboardHidden"

if you want unspecified

 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
kyogs
  • 6,766
  • 1
  • 34
  • 50