机器人,查看生命周期和恢复 [英] Android, View lifecycle and restore

查看:196
本文介绍了机器人,查看生命周期和恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由

this.vehicleListUI = new GameUIVehicleList();
this.vehicleListUI.attachGameEngine(myGameEngine);

这工作对鳍在android破坏和恢复的观点。
而Android可以重新利用该视图的空构造函数,
但我的问题是这个 GameUIVehicleList 将工作我大部分也有 myGameEngine
对象设置为 GameUIVehicleList

This work fin unto the android destroy and restore the view. The Android can recreate the view by use the empty constructor, but my problem is for this GameUIVehicleList will work I most also have the myGameEngine object set to the GameUIVehicleList

myGameEngine 不是序列化,不能这(是UI的一部分)

The myGameEngine is not Serializable and can't be this to ( Is a part of UI )

这存在一种方法,通过全面恢复我查看重新安装 myGameEngine 对象
为创建视图。
这也将有利于使很多新GameUIVehicleList()到一个XML布局文件。

Exist this a way to restore my View fully by reattach the myGameEngine object to a create view. This will also be good for enable a lot of "new GameUIVehicleList()" into a XML layout file.

编辑:

我不知道这是一些帮助,但这样我已经从开始这个问题
我用的是 android.support.v4.app.FragmentActivity ,这保持摧毁和重建
我查看对象。我还可以通过覆盖解决这个问题的方法的一些 android.support.v4.app.FragmentActivity 即调用,而 FragmentActivity 是重新创建/箱片段并为此设置从我的活动,保持必要数据的需要值。

I don't know if this is to some help but way I has this problem from begin is I use a android.support.v4.app.FragmentActivity and this keep to destroy and recreate my View object. I can also fix this by override some method in android.support.v4.app.FragmentActivity that is invoke while FragmentActivity is recreate/crate a fragment and for this set the need value from my Activity that hold the need data.

推荐答案

销毁和活动(和视图)的再创作通常发生在配置变化(通常屏幕方向变化)。您可能要检查是否这篇文章帮助和<一个href=\"http://developer.android.com/reference/android/app/Activity.html#onRetainNonConfigurationInstance%28%29\"相对=nofollow> onRetainNonconfigurationInstance() / setRetainInstance()不会是你的问题的良药。

Destroying and re-creation of Activity (and views) usually happens on configuration change (most often screen orientation change). You may want to check if this article helps and onRetainNonconfigurationInstance()/setRetainInstance() would not be the cure for your problems.

这篇关于机器人,查看生命周期和恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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