Android 当Don';t保持活动选项处于打开状态,onSavedInstanceState在活动A中为空

Android 当Don';t保持活动选项处于打开状态,onSavedInstanceState在活动A中为空,android,state-saving,Android,State Saving,我面临着一个奇怪的问题,它与在Android中保存状态有关。 当我在Android中打开“不保留活动”选项时(来自开发者选项)。然后,如果我从片段A(由活动A启动)启动活动B(启动片段B)。然后在片段A中调用了我的onSavedInstance方法,但在片段A的OnCreate方法中,我收到的bundle为null 而以上手段有时是不一致的(特别是在清除安卓数据时复制) 在SaveInstanceState方法中的活动A中,我使用以下impl-保存了片段A: getSupportFragment

我面临着一个奇怪的问题,它与在Android中保存状态有关。 当我在Android中打开“不保留活动”选项时(来自开发者选项)。然后,如果我从片段A(由活动A启动)启动活动B(启动片段B)。然后在片段A中调用了我的
onSavedInstance
方法,但在片段A的
OnCreate
方法中,我收到的bundle为null

而以上手段有时是不一致的(特别是在清除安卓数据时复制)

在SaveInstanceState方法中的活动A中,我使用以下impl-保存了片段A:

getSupportFragmentManager().putFragment(Bundle,FRAGMENT_TAG,instanceOFFragA);
if (savedInstanceState != null) {
    args = savedInstanceState;
    Fragment fragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_TAG);
    if (fragment != null && fragment.getClass().equals(FragA.class)) {
        instanceOfFragA = (FragA) getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_TAG);
    }
}
同样,在onCreate中,我尝试使用以下impl-检索保存的片段A:

getSupportFragmentManager().putFragment(Bundle,FRAGMENT_TAG,instanceOFFragA);
if (savedInstanceState != null) {
    args = savedInstanceState;
    Fragment fragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_TAG);
    if (fragment != null && fragment.getClass().equals(FragA.class)) {
        instanceOfFragA = (FragA) getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_TAG);
    }
}

但是在
OnCreate
中,我得到了片段C的实例(这基本上是一个注册片段,具有登录和注册按钮,登录单击将启动LoginActivity,inturn将启动LoginFragment。如果登录成功,它将调用启动片段a的活动a(因为登录成功)).

你能发布你的活动A代码吗?@himanshu1496基本上不是活动A,而是片段A。很抱歉,这是我们的生产代码。那么我的朋友,你的问题不清楚。你能发布你的活动A代码吗?@himanshu1496基本上不是活动A,而是片段A。很抱歉,这是我们的生产代码。那么你的问题不是我很清楚,我的朋友。