I'm using mentioned PreferenceCompatFragment
in my code but I have a problem with setting listener on changing settings.
I have made an implementation of OnSharedPreferenceChangeListener
in my Activity
so I have tried to set mentioned listener in a moment when Fragment will be attached to view/container but all time I'm getting null pointer on PreferenceManager.getDefaultSharedPreferences(getActivity());
Most examples are construct with such way that Fragment is implementing also listener - in my case i want to do it separately.
I just found quite simple solution,
onCreatePreferences
- add preferences from resourceonAttach
- assign listener (global variable) from MainActivityonCreate
- getPreferencesManager and register listener