Android and iOS Access to invalidated Collection object

Apps keep on crashing because of Access to invalidated Collection object
How do i check if the object has been invalidated.

if (realmObject != null){. —> crashing over here

}

What SDK are you using and do you have a crash log/exception message that you can share?

So we have the Chat functionality and users can delete the chat. When one user deletes the chat, it will not be visible to other user. Issues occurs when one user deletes the chat and the 2nd is still on that screen

classpath “io.realm:realm-gradle-plugin:10.8.0”

2021-09-13 01:13:09.112 6565-6565/com.app.abc E/REALM_JNI: jni: ThrowingException 9, Access to invalidated Collection object, .
2021-09-13 01:13:09.112 6565-6565/com.app.abc E/REALM_JNI: Exception has been thrown: Access to invalidated Collection object
2021-09-13 01:13:09.113 6565-6565/com.app.abc D/AndroidRuntime: Shutting down VM
2021-09-13 01:13:09.116 6565-6565/com.app.abc E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.abc, PID: 6565
java.lang.IllegalStateException: Access to invalidated Collection object
at io.realm.internal.OsList.nativeSize(Native Method)
at io.realm.internal.OsList.size(OsList.java:285)
at io.realm.ManagedListOperator.size(ManagedListOperator.java:72)
at io.realm.RealmList.size(RealmList.java:599)
at com.app.abc.activity.MessageActivity.onBackPressed(MessageActivity.java:376)
at com.app.abc.activity.MessageActivity.onBackClick(MessageActivity.java:178)
at com.app.abc.activity.MessageActivity_ViewBinding$4.doClick(MessageActivity_ViewBinding.java:90)
at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:18)
at android.view.View.performClick(View.java:7448)
at android.view.View.performClickInternal(View.java:7425)
at android.view.View.access$3600(View.java:810)
at android.view.View$PerformClick.run(View.java:28305)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)