Reputation: 7440
When developing android applications I use Loaders to asynchronously retrieve data from a local SQLite DB through a content provider and update the Views.
When I have to retrieve data from the Internet (i.e. JSON) I use intent services. As the download finishes a broadcast receiver is triggered and the collected data stored through a Content Provider in a local SQLite Db.
Is there any way to trigger loaders execution after the DB is updated? The first time data are downloaded from the Internet I update the UI in the broadcast receiver after having updated the DB but it would be more coherent to do that through the loader as well.
UPDATE
Plase notice that I would like to have an answer based on Android stardard classes (Not libraries from 3rd parties)
Upvotes: 2
Views: 613
Reputation: 3562
Is there any way to trigger loaders execution after the DB is updated?
Yes, just implement the notification mechanism in the ContentProvider
. Basically:
in query()
, before returning the Cursor
call Cursor.setNotificationUri()
in insert()
, delete()
, update()
, notify the changes to the uri with ContentResolver.notifyChange()
See also this other answer of mine.
Upvotes: 3