Skip to content

Commit 746f49a

Browse files
committed
Handle the root cause of this crash: destroying the room on activity recreation
1 parent 3cb72ca commit 746f49a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

appnav/src/main/kotlin/io/element/android/appnav/room/joined/JoinedRoomLoadedFlowNode.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88

99
package io.element.android.appnav.room.joined
1010

11+
import android.app.Activity
1112
import android.os.Parcelable
13+
import androidx.activity.compose.LocalActivity
1214
import androidx.compose.runtime.Composable
15+
import androidx.compose.runtime.mutableStateOf
1316
import androidx.compose.ui.Modifier
1417
import androidx.lifecycle.lifecycleScope
1518
import com.bumble.appyx.core.lifecycle.subscribe
@@ -96,6 +99,9 @@ class JoinedRoomLoadedFlowNode(
9699
private val callback: Callback = callback()
97100
override val graph = roomGraphFactory.create(inputs.room)
98101

102+
// This is an ugly hack to check activity recreation
103+
private val currentActivity = mutableStateOf<Activity?>(null)
104+
99105
init {
100106
lifecycle.subscribe(
101107
onCreate = {
@@ -115,8 +121,12 @@ class JoinedRoomLoadedFlowNode(
115121
},
116122
onDestroy = {
117123
Timber.v("OnDestroy")
118-
activeRoomsHolder.removeRoom(inputs.room.sessionId, inputs.room.roomId)
119-
inputs.room.destroy()
124+
// If we're just going through an activity recreation there's no need to destroy the Room object
125+
// Destroying it would actually cause an issue where its methods can no longer be called
126+
if (currentActivity.value?.isChangingConfigurations != true) {
127+
activeRoomsHolder.removeRoom(inputs.room.sessionId, inputs.room.roomId)
128+
inputs.room.destroy()
129+
}
120130
appNavigationStateService.onLeavingRoom(id)
121131
}
122132
)
@@ -289,6 +299,8 @@ class JoinedRoomLoadedFlowNode(
289299

290300
@Composable
291301
override fun View(modifier: Modifier) {
302+
currentActivity.value = LocalActivity.current
303+
292304
BackstackView()
293305
}
294306
}

0 commit comments

Comments
 (0)