从添加的行中检索ID时遇到了一些问题.
insertWithConflict在我的内部ContentProvider返回新添加的行的ID,但我不知道从ContentProvider我的IntentService负责触发插入的方法.
码
插入 IntentService
Uri uri = Uri.parse(MicroDatabaseProvider.CONTENT_URI + "/" + MicroDatabaseProvider.ORGANIZER_SEARCH_IN);
getContentResolver().insert(uri, cv);
Run Code Online (Sandbox Code Playgroud)
插入 ContetnProvider
long idLong = sqlDB.insertWithOnConflict(DbHelperMicro.ORGANIZER_SEARCH_TABLE,
null,
values,
SQLiteDatabase.CONFLICT_IGNORE);
getContext().getContentResolver().notifyChange(Uri.parse(CONTENT_URI + "/" + ORGANIZER_SEARCH_QUE), null);
Run Code Online (Sandbox Code Playgroud)
您的insert函数ContentProvider应返回如下Uri值:
public Uri insert(Uri uri, ContentValues values) {
//...
return Uri.parse(base_uri+ "/" + id); //where base uri is the base uri from your table
}
Run Code Online (Sandbox Code Playgroud)
如果它像我向您展示的那样,您可以从该URI中检索id.
在您的使用中使用以下代码 IntentService
Uri result = getContentResolver().insert(uri, cv);
long id = Long.parseLong(uri.getLastPathSegment());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2558 次 |
| 最近记录: |