I have a RealmResults object which i am updating but the problem is that it does not get updated in real time.
code...
Thread syncMessages = new Thread(() -> {
final Realm realm = Realm.getDefaultInstance();
ChatManager chatManager = new ChatManager(realm, context);
resultMessages = chatManager.sendPendingMessages(user.getId_user());
countDownLatch.countDown();
realm.close();
});
try {
syncMessages.start();
countDownLatch.await();
} catch (Exception e) {
e.printStackTrace();
}
sendPendingMessages is the function that contains the realmresult object.
RealmResults<ChatMessage> messages = chatRepository.pendingSyncMessages();
//it fetches all chat messages that are not synced.
I create a service to sync data with server and since its on a different thread,i need to open another realm instance to update the data locally so it knows that the data has been synced
OnSuccessCall of the Service
Realm innerRealm = Realm.getDefaultInstance();
ChatRepository innerchatRepository = new ChatRepository(innerRealm);
innerchatRepository.updateSyncForChatMessage();
RealmResults<ChatMessage> messages_middle = innerchatRepository.pendingSyncMessages();
Within the on success of the service the realmresults object reflects the changes correctly so the size of messages_middle is less than messages since data was synced but when i check the size of messages outside the service after it has synced data,it still shows the original size and the original data.