保持数据视图/布局Android的屏幕旋转/活动破坏后, [英] Keeping data view/layout in Android after screen rotate/activity destroyed

查看:345
本文介绍了保持数据视图/布局Android的屏幕旋转/活动破坏后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对活动有点困惑被破坏,当用户的设备旋转重建。

I'm a little confused about the Activity being destroyed and recreated when the user's device is rotated.

我一直在阅读过来,我理解这样做的理由(这基本上是'力量'的开发,以确保他们没有错过在旋转/语言/其他更改任何东西)

I've been reading around, and I understand the rationale for doing so (it basically 'forces' the developer to make sure they haven't 'missed' anything upon rotation/language/other changes)

我很高兴地尊重最好的做法,如果它被看作是这样的,但它引出了一个问题:

I'm happy to respect best practice if it is seen as such, however it begs the question:

我如何记住游戏/应用程序的状态,这样当屏幕旋转时我已经从一些重新生成什么用户在看?

这是我所看到的,绝对的一切都被摧毁,基类的构造函数运行,并在活动所有变量是'空'。

From what I can see, absolutely everything is destroyed, the base class constructor runs and all variables in the Activity are 'null'.

我怀疑'savedInstanceState(捆绑类)是在那里我会收集这些数据,但是看完各地似乎只被用于当应用程序缺乏资源(和其他一些极端边缘的情况下)关闭

I suspect the 'savedInstanceState' (Bundle class) is where I would collect that data, but reading around it only seems to be used for when the app is closed from lack of resources (and a few other extremely fringe cases)

我是误导或误解savedInstanceState的目的是什么?它是明智的放弃最佳实践(让活动被销毁),如果我铭记足以不要错过在旋转时什么?在此先感谢您的任何建议。

Am I misinformed or misunderstanding the purpose of savedInstanceState? Is it wise to abandon best practice (letting the Activity be destroyed) if I'm mindful enough to not miss anything upon rotation? Thanks in advance for any advice.

我要注意这个问题,适用于游戏编程(我不使用布局XML)

推荐答案

你需要你的活动将重现?有没有工作,你想怎么做就轮换? savedInstanceState是要在其中存储要传递给活动的娱乐数据,但由于您没有使用XML的布局,你可以考虑只增加机器人:configChanges =定位到你的活动清单。这会给你手动控制在旋转的变化会发生什么。

Do you need your activity to be recreated? Is there work you want to do on rotation? savedInstanceState is where you would store data to be passed to the recreation of the Activity, but since you aren't using XML layouts you may consider just adding android:configChanges="orientation" to your activity in the manifest. This will give you manual control over what happens during rotation change.

在另外的我原来的意见,我会覆盖键盘是显示配置变化​​以及:

In additional to my original comment, I would override config changes for keyboard being show as well:

android:configChanges="orientation|keyboardHidden"

如果有你想要做的旋转变化,你可以覆盖 onConfigChange ,做任何你需要有工作。

If there is work you want to do on rotation change you can override onConfigChange and do anything you need there.

这很难说,有是当你应该总是重写配置变化的时间,但我经常这样做,当我有资源文件夹的大小和方向的具体没有任何依赖关系,我做了很多的工作方案,并将花太多时间来重新创建。

It's hard to say that there is a time when you should always override config changes, but I often do it when I have no dependency on resource folders that are size or orientation specific and I'm doing a lot of work that would take too much time to recreate.

这篇关于保持数据视图/布局Android的屏幕旋转/活动破坏后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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