相关疑难解决方法(0)

从 DecorView@2da7146[MyActivity] 中找不到 ViewTreeLifecycleOwner

从撰写更新alpha-11alpha-12(或beta-01)后,每当我打开具有撰写视图的活动或片段时,我都会遇到此崩溃。

我正在使用AppCompatActivitywhich implements LifecycleOwner,所以这非常奇怪。

    java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from DecorView@2da7146[MyActivity]
            at androidx.compose.ui.platform.WindowRecomposer_androidKt.createLifecycleAwareViewTreeRecomposer(WindowRecomposer.android.kt:214)
            at androidx.compose.ui.platform.WindowRecomposer_androidKt.access$createLifecycleAwareViewTreeRecomposer(WindowRecomposer.android.kt:1)
            at androidx.compose.ui.platform.WindowRecomposerFactory$Companion$LifecycleAware$1.createRecomposer(WindowRecomposer.android.kt:98)
            at androidx.compose.ui.platform.WindowRecomposerPolicy.createAndInstallWindowRecomposer$ui_release(WindowRecomposer.android.kt:151)
            at androidx.compose.ui.platform.WindowRecomposer_androidKt.getWindowRecomposer(WindowRecomposer.android.kt:199)
            at androidx.compose.ui.platform.AbstractComposeView.ensureCompositionCreated(ComposeView.android.kt:176)
            at androidx.compose.ui.platform.AbstractComposeView.onAttachedToWindow(ComposeView.android.kt:207)
            at android.view.View.dispatchAttachedToWindow(View.java:20014)
            at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3589)
            at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3596)
            at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3596)
            at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3596)
            at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3596)
            at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3596)
            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2223)
            at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1888)
            at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8511)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
            at android.view.Choreographer.doCallbacks(Choreographer.java:761)
            at android.view.Choreographer.doFrame(Choreographer.java:696)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
            at android.os.Handler.handleCallback(Handler.java:873)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:214)
            at android.app.ActivityThread.main(ActivityThread.java:7050)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
Run Code Online (Sandbox Code Playgroud)

我的代码看起来很简单:

    class MyActivity : …
Run Code Online (Sandbox Code Playgroud)

android android-view android-activity kotlin android-jetpack-compose

22
推荐指数
3
解决办法
2080
查看次数

InputMethodService 与 Jetpack Compose - ComposeView 原因:组合到不传播 ViewTreeLifecycleOwner 的视图中

您可以在Github上找到一个示例项目来重现该问题

我一直在尝试使用 Jetpack Compose 作为键盘 UI。最终,当我尝试通过 InputMethodService 膨胀键盘时

class IMEService : InputMethodService() {

    override fun onCreateInputView(): View = KeyboardView(this)
}
Run Code Online (Sandbox Code Playgroud)

通过使用这个视图

class KeyboardView(context: Context) : FrameLayout(context)  {

    init {
        val view = ComposeView(context).apply {
            setContent {
                Keyboard() //<- This is the actual compose UI function
            }
        }
        addView(view)
    }

}
Run Code Online (Sandbox Code Playgroud)

或者

class KeyboardView2 constructor(
    context: Context,

    ) : AbstractComposeView(context) {

  
    @Composable
    override fun Content() {
        Keyboard()
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用键盘时,出现以下错误

class KeyboardView2 constructor(
    context: Context,

    ) : AbstractComposeView(context) {

  
    @Composable …
Run Code Online (Sandbox Code Playgroud)

android android-input-method android-view android-jetpack-compose

13
推荐指数
2
解决办法
5116
查看次数

使用 Jetpack Compose 的键盘被 Compose beta-01 损坏(未从 DecorView 中找到 ViewTreeLifecycleOwner)

这与这个问题相关

如此处所述,能够使用 Jetpack Compose 创建键盘。现在,在我将项目从 升级alpha-11alpha-12代码损坏(并且仍然损坏beta-01)之后,每当我尝试打开键盘时,都会收到以下错误:

 java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from DecorView@aaf805f[InputMethod]
        at androidx.compose.ui.platform.WindowRecomposer_androidKt.createLifecycleAwareViewTreeRecomposer(WindowRecomposer.android.kt:214)
        at androidx.compose.ui.platform.WindowRecomposer_androidKt.access$createLifecycleAwareViewTreeRecomposer(WindowRecomposer.android.kt:1)
        at androidx.compose.ui.platform.WindowRecomposerFactory$Companion$LifecycleAware$1.createRecomposer(WindowRecomposer.android.kt:98)
        at androidx.compose.ui.platform.WindowRecomposerPolicy.createAndInstallWindowRecomposer$ui_release(WindowRecomposer.android.kt:151)
        at androidx.compose.ui.platform.WindowRecomposer_androidKt.getWindowRecomposer(WindowRecomposer.android.kt:199)
        at androidx.compose.ui.platform.AbstractComposeView.ensureCompositionCreated(ComposeView.android.kt:176)
        at androidx.compose.ui.platform.AbstractComposeView.onAttachedToWindow(ComposeView.android.kt:207)
        at android.view.View.dispatchAttachedToWindow(View.java:20105)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3430)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2052)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1745)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7768)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:967)
        at android.view.Choreographer.doCallbacks(Choreographer.java:791)
        at android.view.Choreographer.doFrame(Choreographer.java:726)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:952)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:940)

Run Code Online (Sandbox Code Playgroud)

这很奇怪,因为我已经在 …

android android-jetpack-compose

3
推荐指数
1
解决办法
1428
查看次数