title: Android: Handling orientation changes myself - RelativeLayout is getting messed up
body: <p>In an Android app, I've got an activity that is somewhat complex and may have threads running at certain times which, when finished, will update the UI. As such, having the Activity destroy and create again (due to orientation change) in the middle of one of these threads could lead to the user having to re-try that action, which is bad.</p>
  
  <p>As such, I've decided to handle orientation changes myself by having <code>android:configChanges="orientation|keyboardHidden"</code> in the manifest, and can then override the <code>Activity.onConfigurationChanged(Configuration newConfig)</code> method.</p>
  
  <p>The root layout for this activity is a RelativeLayout.
  Currently, I don't actually do anything in <code>onConfigurationChanged()</code> other than call the super().</p>
  
  <p>After an orientation change, the layout is muddled - some elements which are android:layout_above= are either at the bottom of the screen, or floating way above what they should be floating above.</p>
  
  <p>Does anyone have any ideas as to how to fix this?</p>
  
  <p>I'm aware that if I allowed the activity to restart upon an orientation change, it would then use a layout from res/layout-land/, but restarting the activity really seems to be the wrong way to go here.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I've tried to setContentView(R.layout.displaymap); in the onConfigurationChanged() method and get the following error:</p>
  
  <pre><code>I/WindowManager(  571): onOrientationChanged, rotation changed to 1
  D/StatusBar(  571): updateResources
  E/AndroidRuntime( 3813): android.view.InflateException: Binary XML file line #17: Error inflating class java.lang.reflect.Constructor
  E/AndroidRuntime( 3813):        at android.view.LayoutInflater.createView(LayoutInflater.java:512)
  E/AndroidRuntime( 3813):        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:564)
  E/AndroidRuntime( 3813):        at android.view.LayoutInflater.rInflate(LayoutInflater.java:617)
  E/AndroidRuntime( 3813):        at android.view.LayoutInflater.rInflate(LayoutInflater.java:620)
  E/AndroidRuntime( 3813):        at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
  E/AndroidRuntime( 3813):        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
  E/AndroidRuntime( 3813):        at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
  E/AndroidRuntime( 3813):        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309)
  E/AndroidRuntime( 3813):        at android.app.Activity.setContentView(Activity.java:1626)
  E/AndroidRuntime( 3813):        at com.apps.virtualtravel.DisplayMap.onConfigurationChanged(DisplayMap.java:1065)
  E/AndroidRuntime( 3813):        at android.app.ActivityThread.performConfigurationChanged(ActivityThread.java:3383)
  E/AndroidRuntime( 3813):        at android.app.ActivityThread.handleConfigurationChanged(ActivityThread.java:3449)
  E/AndroidRuntime( 3813):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1762)
  E/AndroidRuntime( 3813):        at android.os.Handler.dispatchMessage(Handler.java:99)
  E/AndroidRuntime( 3813):        at android.os.Looper.loop(Looper.java:123)
  E/AndroidRuntime( 3813):        at android.app.ActivityThread.main(ActivityThread.java:3948)
  E/AndroidRuntime( 3813):        at java.lang.reflect.Method.invokeNative(Native Method)
  E/AndroidRuntime( 3813):        at java.lang.reflect.Method.invoke(Method.java:521)
  E/AndroidRuntime( 3813):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
  E/AndroidRuntime( 3813):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
  E/AndroidRuntime( 3813):        at dalvik.system.NativeStart.main(Native Method)
  E/AndroidRuntime( 3813): Caused by: java.lang.reflect.InvocationTargetException
  E/AndroidRuntime( 3813):        at com.google.android.maps.MapView.&lt;init&gt;(MapView.java:237)
  E/AndroidRuntime( 3813):        at java.lang.reflect.Constructor.constructNative(Native Method)
  E/AndroidRuntime( 3813):        at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
  E/AndroidRuntime( 3813):        at android.view.LayoutInflater.createView(LayoutInflater.java:499)
  E/AndroidRuntime( 3813):        ... 20 more
  E/AndroidRuntime( 3813): Caused by: java.lang.IllegalStateException: You are only allowed to have a single MapView in a MapActivity
  E/AndroidRuntime( 3813):        at com.google.android.maps.MapActivity.setupMapView(MapActivity.java:180)
  E/AndroidRuntime( 3813):        at com.google.android.maps.MapView.&lt;init&gt;(MapView.java:279)
  E/AndroidRuntime( 3813):        at com.google.android.maps.MapView.&lt;init&gt;(MapView.java:254)
  E/AndroidRuntime( 3813):        ... 24 more
  </code></pre>