I'm doing Realm insertions on a extended NotificationListenerService, like this:
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;
}
}
Using Realm newer than v0.88.3, not a single RealmChangeListener
(rcl) gets called if anything gets inserted in NLService
.
I tried attaching rcl's directly to Realm
, RealmResults
and RealmObject
, nothing works.
The App has for example simple rcl's for RealmResults<myRealmObject>.size()
and
several RecyclerAdapters and the rcl inside RealmRecyclerViewAdapter
is never called.
Rerunning queries however works and the "missing data" shows up. Also if anything gets inserted on ui- or any other thread, rcl's get called and "missing data" shows up.
I stayed for months on Realm 0.88.3 because I can not bring it to work with any newer Realm version. With 0.88.3 mRealm.refresh();
was called in NLService, this is not available in newer versions and .waitForChange
blocks endlessly.
Manifest.xml:
<service
android:name=".service.NLService"
android:label="@string/nl_service"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService"/>
</intent-filter>
</service>