当 PreferenceActivity.onResume 中的首选项更改时更新视图 (Android)
我试图使布尔首选项与内容提供程序中的值保持同步,并且除此问题外都取得了很好的成功。当我在 PreferenceActivity
的 onResume()
方法中设置首选项时(因为内容提供程序中的值可能已更改),视图中的复选框仍然反映预onResume
值。
就我而言,这种偏好可能完全是虚拟的,而不是持久的,但如果它需要持续存在才能转动,那也很好。最终目标是我的应用程序首选项中的一个复选框,它反映并更新内容提供程序中的值。
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 value 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑
PreferenceActivity
首先在onRestoreInstanceState()
方法中设置复选框,然后在生命周期的后期调用您的onResume()
方法。尽管您更改了首选项值,但复选框同步代码已经完成。因此,也许您可以重写 onRestoreInstanceState(),更新首选项值,然后最后调用 super.onRestoreInstanceState()。
I suspect the
PreferenceActivity
first sets the checkbox in theonRestoreInstanceState()
method, and then youronResume()
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 callsuper.onRestoreInstanceState()
last.