问题
When using a LoaderManager, do I still manage my database writes the way I have in the past and let the Loader pick up the changes? I am in the process of converting and adding functionality to an app and I am still getting used to the Android platform.
回答1:
If you are using CursorLoader
, and you do all your database updates via the ContentProvider
you used with CursorLoader
, the loader and its Cursor
will be notified of changes, so everything will be handled for you.
If you are not using CursorLoader
, it is your responsibility to somehow update your own Cursor
. For example, my LoaderEx project has a SQLiteCursorLoader
that works directly with a SQLiteOpenHelper
, and it offers insert()
, update()
, delete()
, and execSql()
methods on the Loader, so we can update the Cursor accordingly.
来源:https://stackoverflow.com/questions/9606598/writing-data-managed-by-a-loadermanager