开发者

update view when preference changed in PreferenceActivity.onResume (Android)

I'm trying to keep a boolean preference in sync with a value in a content provider, and succeeding nicely except for this issue. When I set the preference in my PreferenceActivity's onResume() method (because the va开发者_StackOverflow社区lue may have been changed in the content provider), the checkbox in the view still reflects the pre-onResume value.

As far as I'm concerned, this preference could be entirely virtual and not persistent, but if it needs to persist for the wheels to turn that's fine, too. The end goal is a check box in my app's preferences that reflects and updates the value in the content provider.


I suspect the PreferenceActivity first sets the checkbox in the onRestoreInstanceState() method, and then your onResume() method is called later in the lifecycle. Though you change the preference value, the checkbox sync code is already finished.

So maybe you can override onRestoreInstanceState(), update the preference value, and then call super.onRestoreInstanceState() last.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜