Android Rotation (Load Layout) data loss (id and data / Custom Objects etc.) -
i turning view, same horizontally. contains many variables of type textview
, progressbar
, imageview
, etc .. can not load variables when rotated.
i tried do:
android: configchanges = "keyboardhidden | orientation | screensize | screenlayout"
i find methods can save customized classes, progressbar, views "my nothing."
http://i.imgur.com/a1ugd3w.png
when there anyway load landscape (another layout (with same id's)) of not losing data?
to change layout use:
update code 10/04/2015 (0:45 am)
my rotation :
@override public void onconfigurationchanged(configuration newconfig) { super.onconfigurationchanged(newconfig); if (newconfig.orientation == configuration.orientation_landscape) { super.onconfigurationchanged(newconfig); setcontentview(r.layout.activity_1); } else if (newconfig.orientation == configuration.orientation_portrait){ super.onconfigurationchanged(newconfig); setcontentview(r.layout.activity_2); } }
oncreate
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); if (getresources().getconfiguration().orientation == configuration.orientation_landscape) { setcontentview(r.layout.activity_1); } else if (getresources().getconfiguration().orientation == configuration.orientation_portrait){ setcontentview(r.layout.activity_2); }
references : saving android activity state using save instance state can't sabe objects exits of activity. "i think"
the easiest way not specify orientation
configchanges
. correspondingly, not need override onconfigurationchanged
-- can load layout in oncreate
, state should part preserved. if needed state data can stored in onsaveinstancestate
(and restored in oncreate
).