Avoid duplicated messages when activity is in background.

onDestroy is not called when navigating to the next activity or bringing the app to background. That's why the adapter was not set to null and all messages were added another time the next time the activity comes to foreground. With this fix, the adapter is set to null in onStop.

All in all, the adapter handling may not be the best, but will be replaced by Compose anyway..

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2025-02-17 14:59:15 +01:00
parent 5e872564b7
commit 30caa435ae
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B

View File

@ -562,6 +562,7 @@ class ChatActivity :
override fun onStop() {
super.onStop()
active = false
adapter = null
this.lifecycle.removeObserver(AudioUtils)
this.lifecycle.removeObserver(chatViewModel)
}
@ -2677,7 +2678,6 @@ class ChatActivity :
currentlyPlayedVoiceMessage?.let { stopMediaPlayer(it) } // FIXME, mediaplayer can sometimes be null here
adapter = null
disposables.dispose()
}