Update activity if settings have been changed

I have a PreferenceActivity with settings for my application, and I want to update activity if some settings have been changed.

For example, I have a flag that is responsible for the added tab in my layout when the flag is checked. To catch this event, I used OnSharedPreferenceChangeListener. But this listener clicks on this flag every time and does something (your logic) every time, every click, even if the setting really has not changed. I want to update my activity only if the setting has really been changed. If before it was “OFF” and now it has become “ON”, in this case I want to update, but if I changed OFF - ON-OFF, I do not want to update.

How to really catch the change and how to deal with it in action?

Thank!

+3
source share
1 answer

How to really catch the change and how to deal with it in action?

Step # 1: Add OnSharedPreferenceChangeListenerto your core business.

Step # 2: Prepare the data item that you booleaninitially falseswitch when your checkmark changes.

Step # 3: In onStart()or onResume(), if the data item is booleanequal true, update the action and set the data member to false.

+7
source

Source: https://habr.com/ru/post/1773385/


All Articles