I have a ContentProvider. There are my query and insert methods:
@Override
public Uri insert(Uri uri, ContentValues values) {
final int match = sUriMatcher.match(uri);
long id = -1;
switch (match) {
case ARTICLES_LIST:
id = ArticlesDataSource.getInstance().addArticle(values);
break;
}
Log.d(LOG_TAG, "Notify change for URI: " + uri);
getContext().getContentResolver().notifyChange(uri, null);
if (id != -1) {
return ArticleContract.buildArticleWithIdUri(id);
}
return null;
}
and
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
final int match = sUriMatcher.match(uri);
Cursor refCursor = null;
switch (match) {
case ARTICLES_LIST:
refCursor = ArticlesDataSource.getInstance().getAllPreviewArticlesCursor(selectionArgs, selection, selectionArgs, sortOrder);
break;
case ARTICLES_LIST_BY_CATEGORY:
Article.Category category = ArticleContract.getCategoryFromUri(uri);
refCursor = ArticlesDataSource.getInstance().getPreviewArticlesCursorByCategory(selectionArgs, selection, selectionArgs, sortOrder, category);
//Modify uri for correct listener behaviour. Full uri is: content://payspace.ssidit.pp.ua.payspacemagazine/articles/category/categoryName
List<String> segments = uri.getPathSegments();
String lastSegment = segments.get(segments.size() - 2);
String uriStr = uri.toString();
uri = Uri.parse(uriStr.substring(0, uriStr.indexOf(lastSegment) - 1));
break;
default:
throw new UnsupportedOperationException("Unknwon uri: " + uri);
}
Log.d(LOG_TAG, "Registered for observe changes in uri: " + uri.toString());
refCursor.setNotificationUri(getContext().getContentResolver(), uri);
return refCursor;
}
My logs for notifyChange() and setNotificationUri():
Registered for observe changes in uri: content://payspace.ssidit.pp.ua.payspacemagazine/articles
Notify change for URI: content://payspace.ssidit.pp.ua.payspacemagazine/articles
As you can see, uris are equal. Content adds to the database. I don't close a cursor in my code. What can be wrong?
Aucun commentaire:
Enregistrer un commentaire