Android 当数据库变动时更新UI数据 注册观察者监听


/**
* Register an observer for provider status changes - we will need to
* reflect them in the UI.
*/
private void registerObserver() {
getContentResolver().registerContentObserver(
ContactsContract.Contacts.CONTENT_URI, true, mObserver);
getContentResolver().registerContentObserver(
CallLog.Calls.CONTENT_URI, true, mObserver);
}

private void unregisterObserver() {
getContentResolver().unregisterContentObserver(mObserver);
}

private ContentObserver mObserver = new ContentObserver(new Handler()) {

@Override
public void onChange(boolean selfChange) {
isContactChanged = true;
}
};

你可能感兴趣的:(Android 当数据库变动时更新UI数据 注册观察者监听)