调用DialogFragment出现的Can not perform this action after onSaveInstanceState

代码里面用如下的业务场景:进页面并判断是否签到,没有签到就跳转至一个DialogFragment

最开始的做法是如下:

SignInFragment signInFragment = new SignInFragment();

signInFragment.setTargetFragment(LauncherFragment.this,ConstantNewValue.FRAGMENT_RESPONSE_CODE_SIGN);

signInFragment.show(getActivity().getSupportFragmentManager(), "signInFragment");


结果报错

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1377)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1395)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:637)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:616)
at android.support.v4.app.DialogFragment.show(DialogFragment.java:139)
at com.gty.ryt.admin.fragment.LauncherFragment$2.onNext(LauncherFragment.java:112)
at com.gty.ryt.admin.subscribers.ProgressSubscriber.onNext(ProgressSubscriber.java:75)
at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:134)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.call(OperatorObserveOn.java:224)
at rx.android.schedulers.LooperScheduler$ScheduledAction.run(LooperScheduler.java:107)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5288)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:915)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:710)


检查发现show()方法调用的还是fragment.commit()的方法

public void show(FragmentManager manager, String tag) {
mDismissed = false;
mShownByMe = true;
FragmentTransaction ft = manager.beginTransaction();
ft.add(this, tag);
ft.commit();
}


所以针对DialogFragment修改如下

SignInFragment signInFragment = new SignInFragment();

signInFragment.setTargetFragment(LauncherFragment.this,ConstantNewValue.FRAGMENT_RESPONSE_CODE_SIGN);

holder.fragmentManager.beginTransaction().add(signInFragment,"signInFragment").commitAllowingStateLoss();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值