Actually, I have a table for which I am listing for changes using ContentObserver, and in OnChange(), I am triggering a SyncCall.
My requirement is to make a SyncCall only on insert or update operation and if the operation is delete, I dont want to make a SyncCall.
Registering a contentObserver for a table.
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);
My ContentObserver Class.
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();
}
Is there a way to listen for only insert and update operations using ContentObserver?
Or At Least is there a way that I can know what type of operation(insert, update or delete) that triggered the onChange() method in COntentObserver Class?