我在扩展的NotificationListenerService上进行Realm插入,如下所示:
public class NLService extends NotificationListenerService {
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
// building realmObject here
mRealm = Realm.getDefaultInstance();
RealmHelper.saveObj(myRealmObject, mRealm);
// mRealm.waitForChange(); / mRealm.refresh();
mRealm.close();
}
}
public class RealmHelper {
public static RealmModel saveObj(RealmObject realmObject, Realm realm) {
realm.beginTransaction();
RealmObject newRealmObject = realm.copyToRealm(realmObject);
realm.commitTransaction();
return newRealmObject;
}
}
Run Code Online (Sandbox Code Playgroud)
使用领域比v0.88.3更新的,不是单一的RealmChangeListener(RCL如果有的话被插入)被调用NLService.
我试着将rcl直接附加到Realm,RealmResults并且RealmObject没有任何作用.
例如,应用程序具有简单的rcl RealmResults<myRealmObject>.size()和几个RecyclerAdapter,并且RealmRecyclerViewAdapter从不调用rcl内部.
然而,重新运行查询起作用并且显示"缺失数据".此外,如果在ui-或任何其他线程上插入了任何内容,则会调用rcl并显示"缺少数据".
我在Realm 0.88.3上呆了好几个月,因为我无法使用任何更新的Realm版本.在NLService mRealm.refresh();中调用了0.88.3,这在新版本中不可用并且.waitForChange无休止地阻塞.
的Manifest.xml: …