android:configChanges="方向";不适用于片段 [英] android:configChanges="orientation" does not work with fragments

查看:36
本文介绍了android:configChanges="方向";不适用于片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想为 HoneyComb 调整我的一些应用程序.

I am just trying to adapt some of my applications for HoneyComb.

我面临的问题是我的方向改变(横向/纵向)活动被破坏

The issue iI am facing is the destruction of my activity on orientation change (landscape/portrait)

我在使用经典活动时,在manifest中写道:

When I was using a classic activity, I wrote in the manifest:

但是现在,所有这些线路都不起作用了!

But now, all these lines aren't working anymore!

有解决方法吗?

我的代码:

    <activity android:name=".TwitterActivity" android:label="@string/app_name"
        android:configChanges="keyboardHidden|orientation" />

    <activity android:name=".TwitterActivity$AppListFragment"
    android:configChanges="keyboardHidden|orientation"  />

推荐答案

基于我对 Honeycomb 3.0 和兼容性库 (r1) 的经验.

Based on my experience with Honeycomb 3.0 and compatibility library (r1).

configChange="orientation" 确实与片段一起工作,以防止在方向更改时重新创建活动(应用它).如果您不希望在重新创建活动时重新创建 fragment,请在 onCreate 中调用 setRetainInstance.

configChange="orientation" does work with fragments with respect to preventing the activity (to which it is applied) being re-created on an orientation change. If you want the fragment not to be re-created on activity re-creation then call setRetainInstance in onCreate.

除非我遗漏了某些东西,否则我不太清楚您的第二个清单条目,AppListFragment 不是 Fragment 吗?如果是,那么为什么它会在您的清单中列为条目?

Unless I'm missing something I don't quite get your second manifest entry, isn't AppListFragment a Fragment? If so then why is it listed as an entry in your manifest?

请参阅 SO Answer 以了解新的限定符,如果您的目标是这可能会导致此问题sdk 13,建议尝试 android:configChanges="orientation|screenSize"

See SO Answer for new qualifiers which is likely to be causing this if you are targetting sdk 13, suggest trying android:configChanges="orientation|screenSize"

这篇关于android:configChanges="方向";不适用于片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆