gpt4 book ai didi

android - 即使在 android :configChanges is specified? 时,应用程序也会重新创建

转载 作者:行者123 更新时间:2023-11-30 02:36:52 31 4
gpt4 key购买 nike

我在 manifest.xml 中指定了以下标记

<activity android:screenOrientation="fullsensors
android:configChanges="orientation|keyboardhidden|keyboard"
</activity>

android:configChanges="Orientation|keyboardhidden|keyboard" 意味着避免在“方向”或“键盘隐藏/可见”的情况下重新创建应用程序

在我的 App 类中,我调用了所有 Activity 的生命周期回调。我预计当我旋转/重新定位设备时,不会重新创建应用程序。或者换句话说,由于android:configChanges,下面的回调,按顺序不会被调用。回调是 onPause() onStop() onDestroy() onCreate() onStart() onResume() 每次我旋转设备时,都会重新创建应用程序并调用前面提到的生命周期的回调。

有什么解释为什么会这样吗?

最佳答案

这里您没有在 android:configChanges 中包含 screenSize

根据 doc

Caution: Beginning with Android 3.2 (API level 13), the "screen size"also changes when the device switches between portrait and landscapeorientation. Thus, if you want to prevent runtime restarts due toorientation change when developing for API level 13 or higher (asdeclared by the minSdkVersion and targetSdkVersion attributes), youmust include the "screenSize" value in addition to the "orientation"value. That is, you must decalareandroid:configChanges="orientation|screenSize". However, if yourapplication targets API level 12 or lower, then your activity alwayshandles this configuration change itself (this configuration changedoes not restart your activity, even when running on an Android 3.2 orhigher device).

所以如果你想接收 onConfigurationChanged 回调..你必须在 android:configChanges 中添加 screenSize

关于android - 即使在 android :configChanges is specified? 时,应用程序也会重新创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26402025/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com