My app consists of a single activity. It has a navigation drawer which changes fragment in the activity. One of the nav drawer item is Settings screen which is androidx preference fragment and inherits PreferenceFragmentCompat
. App uses MVVM pattern
In my other fragments view model, I call method of repository which gets data from internet and then saves locally using room db and return LiveData<List<MyData>>
which is used to display the UI of fragment.
Now I want this behavior: By default fetch data only from local db and if there is a change in preference then fetch data from internet and save locally also.
so where should I listen from change in pref? I think maybe MainActivity but how will other fragments know about this change?
UPDATE 1 I have four fragments: past, present, future and settings. whenever any of the first three fragments opens, I want to know if preference was changed or not.