I have a custom content provider for an SQLite database in my application, 
but for queries from the application itself I would like to use 
SQLiteDatabase directly.

The question is how to notify cursors about changes in the database. I've 
come up with the solution below.

A select query and setting a notification Uri:

    Cursor cursor = db.rawQuery(QUERY_SELECT, null);
    cursor.setNotificationUri(getContentResolver(), CONTENT_URI);

A simple cursor adapter in a ListActivity:

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
R.layout.list_item, cursor, new String[] {Columns._ID}, new int[] 
{R.id.list_item});
    setListAdapter(adapter);

A delete query:

    SQLiteDatabase db = new DatabaseHelper(context).getReadableDatabase();
    ...
    db.delete(TABLE, WHERE_CLAUSE, WHERE_ARGS);               // or 
update/insert
    getContentResolver().notifyChange(CONTENT_URI, null);

Everything seems to work fine. Is this a good approach?

I'm trying to avoid custom content provider overhead.


-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to