I has a view that is create by
this.vehicleListUI = new GameUIVehicleList();
this.vehicleListUI.attachGameEngine(myGameEngine);
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
The myGameEngine
is not Serializable and can't be this to ( Is a part of UI )
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.
EDIT:
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.
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.
If myGameEngine
is not Serializable
or Parcelable
, I do not believe it is possible to do this reliably.
However if it is ok, for myGameEngine
to sometimes not be recovered you can extend the Application
class with your own custom MyApplication
class which contains the variable myGameEngine
then in your onCreate
you can get the myGameEngine
that saved in your application context.
MyApplication app = (MyApplication) this.getApplicationContext();
this.vehicleListUI.attachGameEngine(app.myGameEngine);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.