Android 上的方向问题

发布于 2024-10-02 04:27:34 字数 107 浏览 0 评论 0原文

目前我正在研究 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岛徒 2024-10-09 04:27:34

当方向改变时,当前活动的 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.

陪你到最终 2024-10-09 04:27:34

您需要将 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文