Android: How to get callback from content provider when data changes?

Let's say I have 3 active actions that can display and add data to ContentProvider. What is the best way to synchronize state between actions? For example, if ActivityA adds a new entry to ContentProvider, I would like ActivityB and ActivityC to be notified so that they can update their view.

+3
source share
1 answer

Use a method ContentResolver.registerContentObserver()for each action and set the appropriate URIs.

You can pass the base content URI for the provider and pass truefor the parameter notifyForDescendents, and your callback will be hit every time it changes.

, , ( ). , ContentResolver.notifyChange() URI .

+3

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


All Articles