Why notify listeners in a content provider query method?

Posted by cbrulak on Stack Overflow See other posts from Stack Overflow or by cbrulak
Published on 2013-06-28T21:25:14Z Indexed on 2013/06/28 22:21 UTC
Read the original article Hit count: 212

Vegeolla has this blog post about content providers and the snippet below (at the bottom) with this line:

cursor.setNotificationUri(getContext().getContentResolver(), uri);

I'm curious as to why one would want to notify listeners about a query operation. Am I missing something?

Thanks

  @Override
  public Cursor query(Uri uri, String[] projection, String selection,
      String[] selectionArgs, String sortOrder) {

    // Uisng SQLiteQueryBuilder instead of query() method
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();

    // Check if the caller has requested a column which does not exists
    checkColumns(projection);

    // Set the table
    queryBuilder.setTables(TodoTable.TABLE_TODO);

    int uriType = sURIMatcher.match(uri);
    switch (uriType) {
    case TODOS:
      break;
    case TODO_ID:
      // Adding the ID to the original query
      queryBuilder.appendWhere(TodoTable.COLUMN_ID + "="
          + uri.getLastPathSegment());
      break;
    default:
      throw new IllegalArgumentException("Unknown URI: " + uri);
    }

    SQLiteDatabase db = database.getWritableDatabase();
    Cursor cursor = queryBuilder.query(db, projection, selection,
        selectionArgs, null, null, sortOrder);
    // Make sure that potential listeners are getting notified
    cursor.setNotificationUri(getContext().getContentResolver(), uri);

    return cursor;
  }

© Stack Overflow or respective owner

Related posts about android

Related posts about android-contentprovider