2

I am using BottomsheetDialogFragment and recently getting crash reports on crashlytics, the stacktrace is -

Fatal Exception: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:2044) at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:2067) at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:680) at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:634) at android.support.v4.app.DialogFragment.dismissInternal(DialogFragment.java:205) at android.support.v4.app.DialogFragment.dismiss(DialogFragment.java:171) at com.khaalijeb.inkdrops.ListBanks.onSuccessResponse(ListBanks.java:322) at com.khaalijeb.inkdrops.App.onSuccessResponse(App.java:800) at com.olive.upi.OliveUpiManager.onSuccessResponse(Unknown Source:970) at com.olive.upi.transport.d$33.onResponse(Unknown Source:16) at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:169) at android.app.ActivityThread.main(ActivityThread.java:6595) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

I don't know what caused this error since it is not happening in some device and not all of them. Did anyone face this problem earlier and how to overcome it?

I have tested this particular code 1000 times but never got one but in the production world, I am getting this error in around 2 3 devices.

How to call commitAllowingStateLoss();? will this fixed the problem?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Aman Verma
  • 3,155
  • 7
  • 30
  • 60
  • Did you try this? https://stackoverflow.com/a/10261449/284308 – Prexx Jan 11 '19 at 14:23
  • What's causing this? did my Activity is being restored again and bottomsheetfragemnt is not able to get restored? – Aman Verma Jan 11 '19 at 15:07
  • Hi @AmanVerma I am also facing the same issue in the production world. Have you found the solution? If yes, then please share it. – abhishek kumar gupta May 09 '20 at 15:15
  • FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction(); BottomSheetDialogFragment Fragment = new BottomSheetDialogFragment(); transaction.add(Fragment, "loading"); transaction.commitAllowingStateLoss(); – Aman Verma May 09 '20 at 20:29

1 Answers1

3

There is BottomsheetDialogFragment#dismissAllowingStateLoss method in the material library that will allow you to fix this problem

fobo66
  • 410
  • 7
  • 20