坚持屏幕旋转后的上下文菜单 [英] Persisting a context menu after screen rotation
问题描述
我有一个活动,它的onCreate方法,它的作用:
I have an activity that on it's onCreate method it does:
registerForContextMenu(theView);
registerForContextMenu(theView);
和在onCreateContextMenu:
and in onCreateContextMenu:
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(blablabla);
这个伟大的工程,但问题是,上下文菜单消失,当屏幕旋转。 如何解决这一问题?
This works great, but the problem is that the context menu disappears when the screen rotates. How to fix this?
感谢您的阅读!
推荐答案
下面是解决方案:
旋转Android把破坏(当文本菜单消失了,因为在默认情况下),然后的onCreate()但是
The contextMenu disappeared because by default when rotating android calls destroy() and then onCreate() but :
如果您不希望机器人要经过正常的活动破坏,和再造的过程;相反,你要处理再造的意见自己,你可以使用android:configChanges在AndroidManifest.xml中的元素属性
If you don't want Android to go through the normal activity destroy-and-recreate process; instead, you want to handle recreating the views yourself, you can use the android:configChanges attributes on the element in AndroidManifest.xml.
<activity
android:name=".SmsPopupActivity"
android:theme="@android:style/Theme.Dialog"
android:launchMode="singleTask"
android:configChanges="orientation|keyboardHidden"
android:taskAffinity="net.everythingandroid.smspopup.popup">
</activity>
这样我的文本菜单没有关闭的时候,我的手机旋转时,由于的onCreate()方法没有被调用。
This way my contextMenu is not closed when my phone rotates, because onCreate() method is not called.
另请参阅:
- 发展方向感知Android应用程序
- <一个href="http://stackoverflow.com/questions/456211/activity-restart-on-rotation-android">activity-restart-on-rotation-android
- Developing Orientation-Aware Android Applications
- activity-restart-on-rotation-android
这篇关于坚持屏幕旋转后的上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!