gpt4 book ai didi

android - 为什么我在Android中“无法暂停 Activity IllegalStateException:必须仅在所有者的初始化阶段创建Restarter”?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:51:12 25 4
gpt4 key购买 nike

我正在使用一个片段活动,有时在crashlytics上,我可以看到一个异常
致命异常:java.lang.RuntimeException:无法暂停活动
下面是我碎片活动的暂停

@Override
protected void onPause() {
super.onPause();
if (EventBus.getDefault().isRegistered(this))
EventBus.getDefault().unregister(this);
}

这是这个崩溃的堆栈跟踪。
Fatal Exception: java.lang.RuntimeException: Unable to pause activity {com.avail.easyloans.android/com.avail.easyloans.feature.marketplace.activities.ActivityMarketplace}: java.lang.IllegalStateException: Restarter must be created only during owner's initialization stage
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3471)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3430)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3402)
at android.app.ActivityThread.access$1300(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1416)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5601)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)

Caused by java.lang.IllegalStateException: Restarter must be created only during owner's initialization stage
at androidx.savedstate.SavedStateRegistryController.performRestore(SavedStateRegistryController.java:59)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2522)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:834)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1227)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1293)
at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManagerImpl.java:2612)
at androidx.fragment.app.FragmentManagerImpl.dispatchPause(FragmentManagerImpl.java:2588)
at androidx.fragment.app.FragmentController.dispatchPause(FragmentController.java:279)
at androidx.fragment.app.FragmentActivity.onPause(FragmentActivity.java:406)
at com.avail.easyloans.feature.marketplace.activities.ActivityMarketplace.onPause(ActivityMarketplace.java:351)
at android.app.Activity.performPause(Activity.java:6467)
at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1312)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3457)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3430)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3402)
at android.app.ActivityThread.access$1300(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1416)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5601)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)

这背后可能的原因是什么?我如何解决这个问题?
*我不能复制这个虫子。

最佳答案

如果在活动中使用fragmnet,则需要删除“开始”活动中活动的所有片段。

 override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main_root)

while (supportFragmentManager.backStackEntryCount > 0) {
supportFragmentManager.popBackStackImmediate()
}

}

您可以在“设置”->“开发人员选项”->“不保留活动”中打开来进行检查

关于android - 为什么我在Android中“无法暂停 Activity IllegalStateException:必须仅在所有者的初始化阶段创建Restarter”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55546606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com