实际上,我有一个表,我正在使用ContentObserver列出更改,在OnChange()中,我正在触发SyncCall。
我的要求是仅在插入或更新操作时进行SyncCall,如果操作是删除,我不想进行SyncCall。
为表格注册contentObserver。
ContentResolver mResolver = context.getContentResolver();
// Construct a URI that points to the content provider data table
Uri mUri = HistoryDetailsContract.HistoryEntries.CONTENT_URI;
/*
* Create a content observer object.
* Its code does not mutate the provider, so set
* selfChange to "false"
*/
TableContnetObserver observer = new TableContnetObserver(null);
/*
* Register the observer for the data table. The table's path
* and any of its sub paths trigger the observer.
*/
mResolver.registerContentObserver(mUri, true, observer);
我的ContentObserver类。
public class TableContnetObserver extends ContentObserver {
public TableContnetObserver(Handler handler) {
super(handler);
}
/*
* Define a method that's called when data in the
* observed content provider changes.
*/
@Override
public void onChange(boolean selfChange, Uri changeUri) {
/*
* Ask the framework to run your sync adapter.
* To maintain backward compatibility, assume that
* changeUri is null.
*/
//ContentResolver.requestSync(GenericAccountService.GetAccount(), HistoryDetailsContract.AUTHORITY, new Bundle());
SyncUtils.TriggerRefresh();
}
有没有办法只使用ContentObserver监听插入和更新操作?
或者至少有一种方法可以让我知道在COntentObserver类中触发了onChange()方法的操作类型(插入,更新或删除)?