0

我對CursorLoader並與內容解析器常規呼叫有點糊塗了:使用內容解析器等Loader類訪問內容嗎?

mUri = getContentResolver().insert(intent.getData(), null);

如果我們想用一個Loader例如在內容提供商中插入數據,而不是就像上面的例子一樣,只是查詢數據。我們應該怎麼做?這是否有必要?

感謝

回答

1

裝載機是不是插入/更新/刪除查詢,只爲加載數據。你想使用的AsyncQueryHandler做這些操作(最好的操作依賴於用戶交互):

AsyncQueryHandler handler = new AsyncQueryHandler(getContentResolver()) { 
    @Override 
    protected void onInsertComplete(int token, Object cookie, Uri uri) { 
     // Do something now that your insert is complete 
    } 
}; 
handler.startInsert(
    0, // token, passed on to onInsertComplete 
    null, // cookie, passed on to onInsertComplete 
    initialValues); // ContentValues to insert 
+0

謝謝ianhanniballake! – Paul