我使用的是自定義的內容提供商,並顯示在一個片段元素的列表CursorLoader有NotifyChange之後再次調用。查詢()是()
首先CursorLoader調用的ContentProvider的查詢()來獲取存儲在我的數據庫中的所有元素。在我的query()函數中,我啓動了一個線程,它執行WebService調用來更新數據庫中的元素。該線程解析WebServices的響應並調用我的ContentProvider的bulkInsert()。
當我bulkInsert()完成後,我打電話有NotifyChange()。
現在發生了什麼:我看到在notifyChange()之後,我的ContentProvider的query()方法再次被調用,導致新的WebService調用等等。
這裏我query()方法在ContentProvider:
...
// Database query
ticketCursor = mDb.query(TBL_TICKET_NAME, projection, selection, selectionArgs, null, null, orderBy);
// set Notification URI
ticketCursor.setNotificationUri(getContext().getContentResolver(), TICKET_CONTENT_URI);
// WebService call --> This starts a new Thread for the WebService call
asyncSoapQuery(where, uri);
return ticketCursor;
我bulkInsert方法是這樣的:
mDb.beginTransaction();
for (ContentValues value : values) {
mDb.insertWithOnConflict(table, null, value, SQLiteDatabase.CONFLICT_REPLACE);
}
mDb.setTransactionSuccessful();
getContext().getContentResolver().notifyChange(TICKET_CONTENT_URI, null);
mDb.endTransaction();
return values.length();
所以,我的問題是,這會導致Web服務調用的無限循環。我想,notifyChange()不再調用內容提供者的query()方法。我只想在我的查詢()中再次執行WS調用,如果用戶在我的用戶界面上點擊「刷新」... 我在這裏錯過了什麼?
在此先感謝您的幫助!
歡迎計算器! –