gpt4 book ai didi

android - 如何在销毁创建周期之间保存 tabhost 选项卡

转载 作者:行者123 更新时间:2023-11-30 04:46:33 25 4
gpt4 key购买 nike

应用程序有一个通过 TabActivity 管理的 tabhost。它可以选择在运行时添加选项卡。

假设在运行时添加了 5 个选项卡并显示了不同的 Activity 。

当我旋转屏幕时, Activity 会经历销毁和创建的循环。我想维护用户在运行时添加的选项卡,以便在此周期内可用。

最佳答案

最简单的方法是更改​​您的 list ,说明您将自己处理方向更改。

<activity
android:name=".MyActivity"
android:configChanges="orientation" />

这样做是告诉系统不要在方向改变时重新创建 Activity 。然后,您可以覆盖 OnOrientationChanged 以修改任何配置更改。

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//put configuration changes here
}

如果不需要任何显式更改,也可以将其省略。

进一步阅读:Android Runtime Changes

关于android - 如何在销毁创建周期之间保存 tabhost 选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4813816/

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