0

I've tried 100 things to solve this, but none of them seem to work for saving text in a TextView when my orientation changes.

On orientation change, none of these functions are ever called:

onRetainNonConfigurationInstance(), 
onRestoreInstanceState(),
onSaveInstanceState()

Note that I have android:configChanges="orientation" in my manifest for this activity so onConfigurationChanged() is called instead of onCreate() since I want onCreate() to only run once.

Anyone have any ideas at all to fix this?

Chris
  • 511
  • 1
  • 4
  • 6
  • check this answer http://stackoverflow.com/questions/6370943/android-random-images-changed-when-device-is-rotated-to-landscape-mode/6371138#6371138 – ingsaurabh Jun 21 '11 at 05:46
  • on orientation change android will called onResume()/onStart() method if that is present in your code. – Sumant Jun 21 '11 at 05:48
  • none of these are really answering how i can save the text in a textview when the orientation changes... – Chris Jun 21 '11 at 05:57
  • Yes it does, you save the text in onPause/onStop and read it back in in onResume/onStart – Hache Jun 21 '11 at 06:10
  • onPause is not called on orientation change – Chris Jun 21 '11 at 06:24

1 Answers1

1

If you specify android:configChanges then all of this methods will not be called. See Activity ConfigurationChanges and Activity.onRetainNonConfigurationInstance(). Only onConfigurationChanged() method will be called.

Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
  • that's pretty much what i said in my primary post, but how can I save the info in the textview so that I can re-insert it after the orientation changes? – Chris Jun 21 '11 at 06:00
  • I just wanted to explain that these methods should not be called... TextView shouldn't be automatically cleared on configuration change. What do you have in `onConfigurationChanged()` method? – Sergey Glotov Jun 21 '11 at 06:06
  • setContentView(R.layout.main) and the findViewById(...) calls to get the objects by id. – Chris Jun 21 '11 at 06:18
  • Save content of TextView before call to setContentView and restore content after findViewById. Also, it is not needed to set the content view in most cases. – Sergey Glotov Jun 21 '11 at 06:25
  • i removed setContentView and the text remained. thanks. Im not even sure why I put hat there. – Chris Jun 21 '11 at 06:43