Skip to content

Commit 9f2db3e

Browse files
authored
Fix Element Call closing automatically on API 34 (#3402)
* Fix Element Call closing automatically on API 34 It seems like registering a user leave hint listener way too early was causing the activity to try to enter PiP erroneously and that led to the activity closing instead.
1 parent 15e4d07 commit 9f2db3e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import androidx.core.app.PictureInPictureModeChangedInfo
4242
import androidx.core.content.IntentCompat
4343
import androidx.core.util.Consumer
4444
import androidx.lifecycle.Lifecycle
45+
import androidx.lifecycle.lifecycleScope
4546
import io.element.android.features.call.api.CallType
4647
import io.element.android.features.call.impl.DefaultElementCallEntryPoint
4748
import io.element.android.features.call.impl.di.CallBindings
@@ -54,6 +55,7 @@ import io.element.android.features.call.impl.utils.CallIntentDataParser
5455
import io.element.android.libraries.architecture.bindings
5556
import io.element.android.libraries.designsystem.theme.ElementThemeApp
5657
import io.element.android.libraries.preferences.api.store.AppPreferencesStore
58+
import kotlinx.coroutines.launch
5759
import timber.log.Timber
5860
import javax.inject.Inject
5961

@@ -128,12 +130,14 @@ class ElementCallActivity :
128130
private fun ListenToAndroidEvents(pipState: PictureInPictureState) {
129131
val pipEventSink by rememberUpdatedState(pipState.eventSink)
130132
DisposableEffect(Unit) {
131-
val onUserLeaveHintListener = Runnable {
133+
val listener = Runnable {
132134
pipEventSink(PictureInPictureEvents.EnterPictureInPicture)
133135
}
134-
addOnUserLeaveHintListener(onUserLeaveHintListener)
136+
lifecycleScope.launch {
137+
addOnUserLeaveHintListener(listener)
138+
}
135139
onDispose {
136-
removeOnUserLeaveHintListener(onUserLeaveHintListener)
140+
removeOnUserLeaveHintListener(listener)
137141
}
138142
}
139143
DisposableEffect(Unit) {

0 commit comments

Comments
 (0)