Hello, I am trying to attach RealmResults listener for observing realtime changes from database but this change Listener code is not even executing
val config = SyncConfiguration.Builder(user!!, "user=${user!!.id}").build()
Realm.getInstanceAsync(config, object : Realm.Callback() {
override fun onSuccess(realm: Realm) {
val result: RealmResults<Task> = realm.where(Task::class.java).findAll()
Log.i("MongoDB","Resulting... ${result.asJSON()}")
// Till this line everything is working we are getting results
// But the below line is not even executing
result.addChangeListener(RealmChangeListener<RealmResults<Task>> {
Log.i("GoogleIO","We are calling")
if (it.isNotEmpty()) {
it.forEach { task ->
realm.copyFromRealm(task).apply {
Log.i("GoogleIO","${task.name} ${task.owner}")
}
}
}
})
}
})
The Whole Code look likes
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val app = App(AppConfiguration.Builder("application-0-btwju").build())
var user = app.currentUser()
if (user == null) {
app.loginAsync(Credentials.anonymous()) {
if (it.isSuccess) user = it.get()
else return@loginAsync
}
}
Log.i("GoogleIO", "LoggedIn")
val config = SyncConfiguration.Builder(user!!, "user=${user!!.id}").build()
Realm.getInstanceAsync(config, object : Realm.Callback() {
override fun onSuccess(realm: Realm) {
val result: RealmResults<Task> = realm.where(Task::class.java).findAll()
Log.i("MongoDB","Resulting... ${result.asJSON()}")
result.addChangeListener(RealmChangeListener<RealmResults<Task>> {
Log.i("MongoDB","We are calling")
if (it.isNotEmpty()) {
it.forEach { task ->
realm.copyFromRealm(task).apply {
Log.i("GoogleIO","${task.name} ${task.owner}")
}
}
}
})
}
})
} }
I am not even getting logs