gpt4 book ai didi

java - FragmentManager 中的 IllegalStateException -> restoreAllState() : Could not find active fragment with index -1

转载 作者:行者123 更新时间:2023-12-03 21:10:58 25 4
gpt4 key购买 nike

我将 AppCompatActivity 与 Fragments 一起使用,并且很可能在屏幕改变方向时发生以下错误:

Caused by java.lang.IllegalStateException Could not find active fragment with index -1



该错误仅发生在 0.1% 的用户中。在这个 Activity 中,我展示了扩展 DialogFragmentsetRetainInstance(true) .我自己无法重现该问题!

也许你知道如何避免这个错误?

堆栈跟踪:
android.support.v4.app.FragmentManagerImpl.restoreAllState (FragmentManager.java:3047)
android.support.v4.app.FragmentController.restoreAllState (FragmentController.java:152)
android.support.v4.app.FragmentActivity.onCreate (FragmentActivity.java:330)
android.support.v7.app.AppCompatActivity.onCreate (AppCompatActivity.java:84)
(see code 2) com.example.BaseActivity.onCreate (BaseActivity.java:76)
(see code 1) com.example.authorization.AuthorizationActivity.onCreate (AuthorizationActivity.java:39)
android.app.Activity.performCreate (Activity.java:6772)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1119)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2715)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2823)
android.app.ActivityThread.handleRelaunchActivity (ActivityThread.java:4655)
android.app.ActivityThread.-wrap19 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1551)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:154)
android.app.ActivityThread.main (ActivityThread.java:6349)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:893)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:783)

代码 1(来自 AuthorizationActivity.java):
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // THIS LINE

setContentView(R.layout.activity_authorization);

db_user = new UserDatabase(this);
db_wedding = new WeddingDatabase(this);


if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().replace(R.id.authorization_container, new AuthorizationMainFragment()).commit();
}

boolean show = getPreferences().getBoolean(SettingsWeddingFragment.KEY_RESTORE_FILL, false);
if (show) {
db_wedding.showFillDefaultDataMessage(runnable);
}
}

代码 2(来自 BaseActivity.java):
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // THIS LINE

Helper.setBootTimeDifference(this);

resetTitle();

preferences = PreferenceManager.getDefaultSharedPreferences(this);
Alert.newInstance(this);

if (!(BaseActivity.this instanceof SplashActivity)) {
BaseActivity.incAdCounter();
}
}

@Override
public void onBackPressed() {
if (getSupportFragmentManager().getBackStackEntryCount() > 0 ) {
if (isVisible()) {
getSupportFragmentManager().popBackStack();
getSupportFragmentManager().beginTransaction().replace(R.id.authorization_container, new AuthorizationMainFragment()).commit();
}
} else {
super.onBackPressed();
}
}

最佳答案

关于java - FragmentManager 中的 IllegalStateException -> restoreAllState() : Could not find active fragment with index -1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54550830/

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