Android 上的方向问题
目前我正在研究 Android 上的音频流。我编写的与流式传输和播放音频相关的所有方法都在 onCreate() 方法中。问题是当我切换到纵向模式时,所有方法都会再次调用。我怎样才能防止这种情况发生?
Currently I am working on audio streaming on android. All method I have written related to streaming and playing the audio is in the onCreate() method. The problem is when ever I change into portrait mode, all methods are called again. How can I prevent this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当方向改变时,当前活动的 Activity 将被销毁并创建一个新的 Activity。
您可以使用
android:configChanges="orientation|keyboardHidden"
阻止方向更改,或者将音频流代码移至服务。When orientation is changed currently active Activity is destroyed and a new one is created.
Either you could prevent orientation change with
android:configChanges="orientation|keyboardHidden"
or move audio streaming code to a Service.您需要将
android:configChanges="orientation"
放在您的活动清单上。这将阻止它再次调用 Oncreate。You need to
android:configChanges="orientation"
this on your Manifest to your activity. That will stop it from calling Oncreate again.