New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(Android) Using coroutines when creating a child crashes the app if the component context is created using defaultComponentContext()
#195
Comments
The stack trace suggests that the navigation is performed on a background thread. The navigation must be always performed on the main thread. But without a reproducer code it's hard to say where is the mistake exactly. |
What I did that caused the issue was simply pushing a configuration to my stack navigation inside a coroutine. I know this can be solved simply by adding a |
Thanks for reporting. This is expected, we have to explicitly switch to the main despatcher before navigating. |
I have the same problem but in compose desktop. Logs are as follows Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Access from different threads is detected, must be on the main thread only.Current thread: AWT-EventQueue-0. First thread: DefaultDispatcher-worker-1.
at com.arkivanov.decompose.AssertMainThreadKt.assertMainThread(AssertMainThread.kt:8)
at com.arkivanov.decompose.value.MutableValueImpl$special$$inlined$observable$1.afterChange(Delegates.kt:71)
at kotlin.properties.ObservableProperty.setValue(ObservableProperty.kt:41)
at com.arkivanov.decompose.value.MutableValueImpl.setValue(MutableValueBuilder.kt:21)
at com.arkivanov.decompose.router.children.ChildrenFactoryKt.children$onAfterNavigate(ChildrenFactory.kt:106)
at com.arkivanov.decompose.router.children.ChildrenFactoryKt.access$children$onAfterNavigate(ChildrenFactory.kt:1)
at com.arkivanov.decompose.router.children.ChildrenFactoryKt$children$eventObserver$1.invoke(ChildrenFactory.kt:124)
at com.arkivanov.decompose.router.children.ChildrenFactoryKt$children$eventObserver$1.invoke(ChildrenFactory.kt:119)
at com.arkivanov.decompose.Relay$queue$1.invoke(Relay.kt:13)
at com.arkivanov.decompose.Relay$queue$1.invoke(Relay.kt:12)
at com.arkivanov.decompose.SerializedQueue.drain(SerializedQueue.kt:23)
at com.arkivanov.decompose.SerializedQueue.offer(SerializedQueue.kt:17)
at com.arkivanov.decompose.Relay.accept(Relay.kt:25)
at com.arkivanov.decompose.router.stack.DefaultStackNavigation.navigate(DefaultStackNavigation.kt:11)
at com.arkivanov.decompose.router.stack.StackNavigatorExtKt.bringToFront(StackNavigatorExt.kt:82)
at com.arkivanov.decompose.router.stack.StackNavigatorExtKt.bringToFront$default(StackNavigatorExt.kt:81)
at component.app.AppRootComponentImpl.gotoWindow(AppRootComponentImpl.kt:102)
at component.app.AppRootComponentImpl$child$1.invoke(AppRootComponentImpl.kt:52)
at component.app.AppRootComponentImpl$child$1.invoke(AppRootComponentImpl.kt:51)
at component.login.root.LoginRootComponentImpl.openDashboardWindow(LoginRootComponentImpl.kt:151)
...
CommonButton(
modifier = Modifier
.width(418.dp)
.height(56.dp)
.align(Alignment.End),
onClick = {
component?.openDashboardWindow()
},
text = "Go to Dashboard",
... |
@bennysway This check that you're encountering is actually added in a recent version, here. |
Yes, and also make sure that you create the root
Reopening the issue to mention this in the docs. |
Docs updated in 6b10c44. |
Isn't the UI thread the thread in which the program executes by default before entering any coroutines, like in Android? |
@YektaDev unfortunately no, the program starts on the main thread, and then Swing starts it's own UI thread. All event callbacks in Compose are called on the UI thread. |
Hi. I just found out that in order to create a Decompose component context using the
defaultComponentContext
function, which useslifecycle.EssentyLifecycleInterop.subscribe
underneath, breaks the app (most likely because of its interaction withandroidx.lifecycle
), and the workaround is to either not use coroutines when creating a child or create the child inDispatchers.Main
. Otherwise the app crashes immediately with error logs similar to this (Replaced app package withcom.company.app
):MainActivity.kt
:Emulator:
Pixel 4 XL API 25 (Android 7.1.1 Google APIs | x86)
Just wanted to report this (edge?) case.
The text was updated successfully, but these errors were encountered: