1

Rotating screen, my listview disappears. (API 19). I have a list adapter, db helper that I initialize in onCreate() in my ListActivity. Rotating screen, my listview disappears. Per https://stackoverflow.com/a/2902944/398348, I tried

 <activity
    android:name="com.mypkg.MyListActivity"
    android:label="@string/app_name" 
    android:configChanges="keyboardHidden|orientation" >

It made no difference.

Also I am trying to understand - if my variables (list adapter etc) are recreated in onCreate(), then won't this be run anyway when activity is destroyed and recreated? Why do I need to do it again in onSaveInstanceState?

Community
  • 1
  • 1
likejudo
  • 3,396
  • 6
  • 52
  • 107
  • 1
    http://stackoverflow.com/a/9550231/3286163 – singularhum May 07 '14 at 23:40
  • As to the second part of your question, I think that this will require that you post your code. – Michael Alan Huff May 08 '14 at 00:01
  • @singularhum the accepted answer in your link says that one should also implement this method - for a list activity, what would that mean for the layout resource file? `android:configChanges="keyboardHidden|orientation|screenSize" Then within the Activity override the onConfigurationChanged method and call setContentView to force the GUI layout to be re-done in the new orientation. @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); setContentView(R.layout.myLayout); }` – likejudo May 08 '14 at 00:39
  • 2
    @likejiujitsu you only need to override it if you want to manually adjust the layout (or do whatever you need) when the orientation changes. Refer to the documentation [here](http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange) – singularhum May 08 '14 at 00:45
  • @singularhum your answers are remarkably clear and informative. Please keep it up. – Michael Alan Huff May 08 '14 at 01:23
  • @MichaelAlanHuff Thanks but are you up-voting all my answers? This won't work anyway (will get reverted). If not sorry, someone is doing it. You can refer to [serial voting](http://meta.stackexchange.com/questions/126829/what-is-serial-voting-and-how-does-it-affect-me). – singularhum May 08 '14 at 01:30
  • @singularhum that was me, I haven't had it get reverted before. Then again, I've not done that sort of thing in such quantity for a user before. I'll refrain from such things in the future. – Michael Alan Huff May 08 '14 at 01:39
  • @MichaelAlanHuff Yeah you did quite a bit in a short time-span so it will most likely get reverted in the next day or so as mentioned in the link in my last comment. At least you know now though. I appreciate the gesture nonetheless. – singularhum May 08 '14 at 01:58

1 Answers1

2

For the first part of your question try changing the configChanges to

android:configChanges="orientation|screenSize"

This is because when you switch orientation, the screen size changes as well.

Michael Alan Huff
  • 3,462
  • 3
  • 28
  • 44