I have an app that allow users to edit the ContractsContacts
DB.
When a user edits the ContractsContacts
DB using the functions of my app, I don't want that my ContentObserver
is aware of that changes.
I want my ContentObserver
to be aware only of changes generated from other apps. For example when users edit ContractsContacts
DB by using the mobile apps.
So, my question is: is there a way to tell the ContentObserver
"hey, don't listen to this change, because I'm aware of it, dont call your onChange()
method":
The only solution I found is:
ContentObserver
before starting the "edit function" of my appContentObserver
after my function did all its work.Thank you
This is not your ContentProvider
, and so you cannot prevent Android from updating registered observers. Your observer is nothing special to Android.
So, in addition to your unregister-modify-register flow, you could tell your observer to ignore the next update (have it track that in a boolean
or something), then modify the data. The observer would skip whatever work it normally does when that boolean
is set, just flipping it to false
to pick up future changes.
Both of these suffer from race conditions (you and another app modifying the provider at the same time).
Ideally IMHO, you modify whatever logic is being triggered by the observer to live with triggers coming from your own updates, so that all changes of the data are treated equally, whether coming from your app or not.