android:configChanges="方向"不适用于片段
我只是想调整我的一些应用程序以适应 HoneyComb。
我面临的问题是我的活动在方向变化(横向/纵向)时被破坏
当我使用经典活动时,我在清单中写道:
但现在,所有这些线路都不再起作用了!
有解决方法吗?
我的代码:
<activity android:name=".TwitterActivity" android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation" />
<activity android:name=".TwitterActivity$AppListFragment"
android:configChanges="keyboardHidden|orientation" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
基于我使用 Honeycomb 3.0 和兼容性库 (r1) 的经验。
configChange="orientation"
确实可以与片段一起使用,以防止在方向更改时重新创建活动(它所应用的活动)。如果您希望在重新创建 Activity 时不重新创建fragment
,请在onCreate
中调用setRetainInstance
。除非我遗漏了一些东西,否则我不太明白你的第二个清单条目,
AppListFragment
不是一个Fragment
吗?如果是这样,那么为什么它会被列为清单中的一个条目?请参阅 SO Answer 了解新的限定符,如果您的目标是 sdk 13,则可能会导致此问题,建议尝试
android:configChanges="orientation|screenSize"
Based on my experience with Honeycomb 3.0 and compatibility library (r1).
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 thefragment
not to be re-created on activity re-creation then callsetRetainInstance
inonCreate
.Unless I'm missing something I don't quite get your second manifest entry, isn't
AppListFragment
aFragment
? If so then why is it listed as an entry in your manifest?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"
我遇到了一个非常相似的问题,但必须进行一些添加才能使其适用于各种版本(包括 ICS)。
在主应用程序活动中,我添加了与 Jason 提供的版本略有不同的版本。
我在 Honeycomb 之前就已经这样做了:
我必须制作第一个示例才能使其在所有版本上运行。我目前正在使用片段和 ActionBarSherlock 来实现向后兼容性。
我还更改了保存和重新加载的方式:
保存实例状态方法的代码:
希望这会有所帮助。
I had a very similar problem but had to make a couple of additions to get it to work with various version (including ICS).
In the main app activity I added a slightly different version of what Jason offered.
I had this working on pre-Honeycomb with:
I had to make the first example to get it running on all versions. I'm currently using fragments and ActionBarSherlock for backwards compatibility.
I also changed the way I was saving and reloading:
The code for the save instance state method:
Hope this helps.
到 API 13 为止,configChanges 属性有了一个新值
screenSize
因此,如果您使用大屏幕,请确保在 configChanges 属性中添加 screenSize:
Up to API 13 there was a new value to the configChanges attribute,
screenSize
So if you're using large screens make sure to add screenSize in your configChanges attribute:
即使没有碎片,我也遇到了同样的问题(即活动重新启动)。
我将: 更改
为:
防止活动重新启动。
I was having this same problem (i.e., activity restarting) even without fragments.
I changed:
to:
That prevent the activity from restarting.
我知道这是一个很晚的答案,但我最近遇到了这个问题,并且能够解决片段活动的问题。
1) 在清单中,
2) 在类文件中,重写 onSaveInstanceState(Bundle outState)。
就是这样!享受 :)
I know this is quite late answer, but I recently faced this issue and was able to resolve this for Fragment Activity.
1) In Manifest,
2) In Class file, override the onSaveInstanceState(Bundle outState).
Thats it! Enjoy :)
在清单文件中,在活动内部添加此行
In Manifest file, inside activity add this line
将此添加到 Manifeast.Xml
它适合您。
Add this to Manifeast.Xml
Its work for you.