android - Best practice for handling state change during screen rotation -
i've got simple program spinner , togglebutton. when button toggled on disable spinner, , enable when toggle off. i've come across issue means spinner re-enabled during screen rotation. understand due activity state changing , oncreate being called again, haven't come across definitive answer on best practice view states in instances this.
note: relevant questions relating i've found below. 3 have discussions on how handle state changes (onpause/onresume versus overriding onsaveinstancestate), none seem clarify preferred option simple this.
losing data when rotate screen
the accepted answer @ saving android activity state using save instance state way go.
use onsaveinstancestate
save boolean flag indicating whether spinner disabled, read flag in oncreate
(or onrestoreinstancestate
) , disable spinner necessary.
if give views android:id
in xml layout , don't explicitly set android:saveenabled
false, "state" saved , restored automatically. example, text views, includes text in view , position of cursor. appears enabled/disabled status not part of "state", however.
Comments
Post a Comment