简体   繁体   中英

Text to speech and Orientation change

My application makes heavy use of the Text to Speech API .

It is a game which leads the player to change the orientation frequently. I do have different layouts for portrait and landscape and this is ok.

I use onRetainNonConfigurationInstance() and onCreate() to keep the state.

However, there is one fact that causes problems:

I am calling tts.shutdown() in onDestroy() which I think is necessary to free resources properly. However, this causes the current text and all queued messages to be lost when the user changes the orientation. As the Text-to-Speech object has a reference on the " old " activity, I cannot transfer it to the new activity.

How can I solve this problem?

这对于Application类可能是一个很好的用法,您可以在onCreate()初始化TTS(并忽略它,因为在实际设备上不会调用onTerminate())。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM