I am a newbie Realm on the android platform, my application observes the list of employees and then displays newly inserted employees into the view. Here is the code I use to get the list of newly inserted employees:
backGroundRealm = Realm.getInstance(employeeRealmConfig)
insertionEmployeeList.clear()
val queryEmployeesTask = backGroundRealm.where<Employee>().findAll()
changeSet?.let { orderedCollectionChangeSet ->
//Handle data when there are inserted records
for (range in orderedCollectionChangeSet.insertionRanges) {
for (index in range.startIndex until range.startIndex + range.length) {
GLog.d(TAG, "insertionRanges index $index")
if(index < queryEmployeesTask.size) {
queryEmployeesTask[index]?.let {
GLog.d(TAG, "add ${it.name} to list")
insertionEmployeeList.add(it)
}
}else{
GLog.d(TAG,"insert new employee at $index but size is ${queryEmployeesTask.size}")
}
}
}
}
Running the application then check the log file I found below the line of logs
insertionRanges index 35295
insert new employee at 35295 but size is 35295
insertionRanges index 35296
insert new employee at 35296 but size is 35295
insertionRanges index 35297
insert new employee at 35297 but size is 35295
I wanna know why queryEmployeesTask size = 35295 but changeSet has insertionRanges's index = 35295,35296,35297. How to get the employee info at index 35295,35296,35297. Thanks, bro