Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
目前我正在研究android上的音频流。我编写的所有与流式传输和播放音频相关的方法都在 onCreate() 方法中。问题是当我更改为纵向模式时,所有方法都会再次调用。我怎样才能防止这种情况?
当方向改变时,当前活动的 Activity 被销毁并创建一个新的。
您可以阻止方向更改android:configChanges="orientation|keyboardHidden"或将音频流代码移动到服务。
android:configChanges="orientation|keyboardHidden"
您需要android:configChanges="orientation"在您的活动清单上注明这一点。这将阻止它再次调用 Oncreate。
android:configChanges="orientation"