Search code examples
androidandroid-contentprovider

Automatic update for CursorAdapter is only for ContentProvider?


I've a listview with a cursoradapter. I've also a SQLite database. Here is my question: Is it possible that the auto-update works only with a ContentProvider and not with SQLite only?


Solution

  • Cursors are never updated, automatically or otherwise. They are not modified due to changes in wherever the Cursor came from.

    If you are using the loader framework, with CursorLoader, then you will get a fresh Cursor delivered to you when data changes, if:

    • You are querying a ContentProvider, and
    • The ContentProvider is written to support ContentObservers

    However:

    • This is a different Cursor than before, requiring you to pass that to your CursorAdapter
    • This does not work with other sources of Cursors (e.g., SQLite queries, MatrixCursor)
    • This does not work if you query the ContentProvider by other means (e.g., query() on a ContentResolver)