暂停方向改变

发布于 2024-10-12 08:51:02 字数 220 浏览 2 评论 0原文

文档中说:“配置更改(例如屏幕方向、语言、输入设备等的更改)将导致您当前的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花开柳相依 2024-10-19 08:51:02

首先,为什么不解决最初的问题?

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:

Note: Handling the configuration
change yourself can make it much more
difficult to use alternative
resources, because the system does not
automatically apply them for you. This
technique should be considered a last
resort and is not recommended for most
applications.

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 :)

送舟行 2024-10-19 08:51:02

如果您始终想要特定的方向,则可以将 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);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文