I have a ContentProvider backed up by SQLiteDatabase and it has a rather common implementation, i.e:
class MyContentProvider extends ContentProvider {
public void update(...) {
// write stuff to DB
//...
// done writing stuff
getContentResolver().notifyChange(uri,null);
}
}
I also use a CursorLoader
to perform query and display its results in adapter/listview.
No thread synchronization is done in my ContentProvider.
It is not very clear for me what happens in the following case:
- I start some custom non-ui thread and call
update()
to change some values in DB inside this thread. - This
update()
causesnotifyChange(...)
to be called - My
CursorLoader
picks up this change and updates adapter, which updates aListView
Is the above scenario OK from a thread-safety perspective? I mean, look, values are written using one thread (non-ui), then same thread notifies about changes and lastly changes are picked up by CursorLoader
which I suspect uses some other background thread to load its data.
Do I need to do some manual thread synchronization or will it just work? (Android may already be smart about all this stuff)