@Nullable @Override public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder){ // 执行数据的增删改查前先验证请求的 URI 和预留的 URI 是否匹配 if (uriMatcher.match(uri) == MATCH_CODE){ Cursor cursor = demoData.queryData(); return cursor; } returnnull; }
@Nullable @Override public String getType(@NonNull Uri uri){ returnnull; }
@Nullable @Override public Uri insert(@NonNull Uri uri, @Nullable ContentValues values){ if (uriMatcher.match(uri) == MATCH_CODE){ demoData.insertData(values); notifyChange(); } returnnull; }
@Override publicintdelete(@NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs){ if (uriMatcher.match(uri) == MATCH_CODE){ int deleteCount = demoData.deleteData(); notifyChange(); return deleteCount; } return0; }
@Override publicintupdate(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection, @Nullable String[] selectionArgs){ if (uriMatcher.match(uri) == MATCH_CODE){ int updateCount = demoData.updateData(); notifyChange(); return updateCount; } return0; }