不要重新加载应用程序时的方向变化 [英] Don't reload application when orientation changes

查看:139
本文介绍了不要重新加载应用程序时的方向变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多关于这个的讨论,但坦率地说,他们都是pretty的先进而作为一个新手到Android的发展,我不能做这项工作。

There are a lot of discussions on this but quite frankly they are all pretty advanced and as a newbie to Android development I can't make this work.

我根本什么都不缺的时候,屏幕旋转来改变。我的应用程序显示一个随机图像时,第一次加载和转动装置应的没有的选择另一种随机图像。我怎样才能(简单)使得这种行为阻止?

I simply need nothing to change when the screen is rotated. My app displays a random image when it first loads and rotating the device should not select another random image. How can I (simply) make this behavior stop?

推荐答案

通常有三种方法可以做到这一点:

There are generally three ways to do this:

  1. 由于一些答案建议,你可以区分是第一次被创建的活动情况,并从 savedInstanceState 正在恢复。这是通过覆盖完成的onSaveInstanceState 和检查的onCreate 的参数。

  1. As some of the answers suggested, you could distinguish the cases of your activity being created for the first time and being restored from savedInstanceState. This is done by overriding onSaveInstanceState and checking the parameter of onCreate.

您可以锁定一个方向活动中加入安卓screenOrientation =画像(或景观)以<活性GT; 在你的清单。

You could lock the activity in one orientation by adding android:screenOrientation="portrait" (or "landscape") to <activity> in your manifest.

您可以告诉你的意思来处理自己的屏幕变化,通过指定系统安卓configChanges =方向|屏幕尺寸&LT;活性GT; 标记。这样的活动将不会被重建,但会收到一个回调,而不是(你可以忽略,因为它不是对您​​有用)。

You could tell the system that you meant to handle screen changes for yourself by specifying android:configChanges="orientation|screenSize" in the <activity> tag. This way the activity will not be recreated, but will receive a callback instead (which you can ignore as it's not useful for you).

我个人倒有去(3)。当然,如果锁定应用程序的方向之一是细跟你,你也可以去使用(2)。

Personally I'd go with (3). Of course if locking the app to one of the orientations is fine with you, you can also go with (2).

这篇关于不要重新加载应用程序时的方向变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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