暂停方向改变
文档中说:“配置更改(例如屏幕方向、语言、输入设备等的更改)将导致您当前的 Activity 被销毁,经历 onPause()、onStop() 和 onDestroy 的正常 Activity 生命周期过程()”。
我想暂停方向更改,因为如果它是在 aa 循环(读取文件)的中间完成的,它会使我的应用程序崩溃。
我该怎么做?另外 - 寻找某种“onOrientationChnage”功能:)
Documentation says: "a configuration change (such as a change in screen orientation, language, input devices, etc) will cause your current activity to be destroyed, going through the normal activity lifecycle process of onPause(), onStop(), and onDestroy()."
I would like to suspend the orientation change, since it crashes my app if it was done in the middle of a a loop (of reading a file).
How can I do this? Also - looking for some kind of "onOrientationChnage" function :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,为什么不解决最初的问题?
90% 的情况下,您所面临的问题(当改变方向时)可以在这个问题中解决:
后台任务、进度对话框、方向更改 - 是否有 100% 有效的解决方案?
阅读它,更正您的代码,看看问题是否消失!
如果您仍然想这样做:
引用文档:
还想做吗?阅读以下链接(我也在那里找到了引文):
http://developer.android.com/guide/topics/ resources/runtime-changes.html#HandlingTheChange
如果您依赖 Android 系统在纵向/横向模式下使用不同的布局,您需要开始自己处理这些差异。如果您不使用这些功能,您可能会什么也不做就可以逃脱:)
First, why not solve the initial problem instead?
90% of the times, the problem that you are facing (when changing orientation) is solved in this question:
Background task, progress dialog, orientation change - is there any 100% working solution?
Read it, correct your code and see if the problems are gone!
If you still want to do it anyway:
Quoting the documentation:
Still want to do it? Read the following link (where I also found the quotation):
http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange
If you rely on android system to use different layouts when you are on portrait/landscape mode, you'll need to start to handle these differences by yourself. If you don't use these features, you may get away without doing nothing fancy :)
如果您始终想要特定的方向,则可以将
android:screenOrientation="portrait"
(或="landscape"
)添加为清单中标记的属性。在运行时这时,您可以调用
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
If you always want a particular orientation, you can add
android:screenOrientation="portrait"
(or="landscape"
as an attribute to your tag in the manifest.At run time, you can call
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);