android - OnRestoreInstanceState() not applied on View IDs that have been set programmatically -
i have viewgroup programmatically instantiates , assigns id viewpager. on rotation, "up" button , changing screen orientation recreate views -- doesn't remember last page index of viewpager.
i've verified onsaveinstancestate() , onrestoreinstancestate() both being called, , both of them contain correct page index information. but, viewpager gets reset page index 0 regardless. notice message in console
no package identifier when getting name resource number [id programmatically defined]
as experiment, defined viewpager (along id) in xml. correctly set viewpager last page index.
so, suspect android framework can't restore last state correctly because id doesn't persist when viewgroup viewpager gets destroyed.
how can work? i'd contain state relating things within viewgroup (eg avoid keeping track of viewpager position in fragment). but, doesn't seem can work unless can make id persist (if that's root cause).
edit: there race condition in code. after ensuring have unique id, worked perfectly.
it seemed me (for odd reason), id of less 10 return incorrect instance data (possibly view) onrestoreinstancestate() of viewpager.
really weird since used findviewbyid
prior setting id ensure id unique. but, there race condition or i'm missing.
anyways, setting id 10 or greater gave correct behavior, , position of viewpager persists between orientation change.
Comments
Post a Comment