开发者

Refresh activity if preferences was changed

I have a PreferenceActivity with settings for my app and I want to refresh activity if some preferences was changed.

For example I have a checkbox which responsible for addtional tab in my layout, when checkbox is checked tab must be shown. To catch this event I used OnSharedPreferenceChangeListener. But this listener listen every click on this checkbox and do something (your logic) every time, every click even though setting really was not changed. I want to refresh my activity only if setting was really changed. If earlier was "OFF" and now become "ON" in this case I want to refresh, but if I changed OFF 开发者_开发问答- ON - OFF I don't want to refresh.

How to catch really changes and how to handle this in activity?

Thanks!


How to catch really changes and how to handle this in activity?

Step #1: Implement the OnSharedPreferenceChangeListener on your main activity.

Step #2: Maintain a boolean data member, initially false, which you toggle whenever your checkbox of interest is changed.

Step #3: In onStart() or onResume(), if the boolean data member is true, refresh the activity and set the data member to false.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜