文本转语音和方向更改
我的应用程序大量使用Text to Speech API
。
这是一款导致玩家频繁改变方向的游戏。我确实有不同的纵向和横向布局,这没关系。
我使用 onRetainNonConfigurationInstance() 和 onCreate() 来保持状态。
然而,有一个事实会导致问题:
我在 onDestroy()
中调用 tts.shutdown()
,我认为这是正确释放资源所必需的。但是,当用户更改方向时,这会导致当前文本和所有排队的消息丢失。由于 Text-to-Speech 对象具有对“旧”活动的引用,因此我无法将其转移到新活动。
我该如何解决这个问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对于
Application
类,您可以在onCreate()
中启动 TTS(忘记它,因为在真实设备上不会调用 onTerminate())。This could be a good use for the
Application
class, where you initiate the TTS inonCreate()
(and forget about it, as onTerminate() is not called on real devices).