0

I am a complete beginner, working on my first app which includes TTS. Everything works as I would like normally, but if I rotate the screen, I get my TTS speak repeated. If I rotate back again, then the TTS is spoken three times. So screen rotation with its destroy/create seems to be giving me another instance of TTS each time. Reading the previous posts, I think I should try onRetainNonConfigurationInstance, but I don't know enough to do that. What would the code look like?

Charles
  • 50,943
  • 13
  • 104
  • 142
gotok
  • 77
  • 1
  • 5

1 Answers1

1

I think what may be happening is that your activity gets recreated when you change screen orientation. This means onCreate and everything in it is executed again.

You can change this behavior by adding android:configChanges="keyboardHidden|orientation" to your activity tag in the manifest and implementing onConfigurationChanged. Please see the answer below for more details on how to do this (ignore everything related to InitializeUI() in the code).

https://stackoverflow.com/a/4589926/483708

Community
  • 1
  • 1
Theo
  • 5,963
  • 3
  • 38
  • 56