Realm.io [Java]通知 - 如何仅在某些表中监听更改? [英] Realm.io [Java] notifications - How to listen for changes only in certain Table?
问题描述
我在realm java文档中看到这个示例代码。
I see this example code in realm java documentation.
public class MyActivity extends Activity {
private Realm realm;
// A reference to RealmChangeListener needs to be held to avoid being
// removed by the garbage collector.
private RealmChangeListener realmListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
realm = Realm.getDefaultInstance();
reamlListener = new RealmChangeListener() {
@Override
public void onChange() {
// ... do something with the updates (UI, etc.) ...
}};
realm.addChangeListener(realmListener);
}
@Override
protected void onDestroy() {
super.onDestroy();
// Remove the listener.
realm.removeChangeListener(realmListener);
// Close the realm instance.
realm.close();
}
}
我有一些数据库模式包含几个表。数据总是在这些表中改变,但我只有一个表,我需要监听和刷新UI与这个表相关。我不想检查这是在Realm的更改在任何其他Realm对象中的任何小更新后完全在期望表。
您可以建议哪些最佳做法?
I have some database schema contain several tables. Data is always changing in these tables but I have only the one table I need to listen and refresh UI related to this table. I don't want to check is this changes in Realm was exactly in wanted table after any little updating in any other Realm Objects. What best practices can you suggest?
推荐答案
直到Realm具有精细粒度的通知,系统,通过使用ContentObserver,RxJava或您自己的Observer接口。
Until Realm has fine-grained notifications, I would implement my own notification system either by using ContentObserver, RxJava or your own Observer interfaces.
这篇关于Realm.io [Java]通知 - 如何仅在某些表中监听更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!