crisp-im / crisp-sdk-android

:package: Crisp Android SDK, add a chat in any Android app and communicate with your users.
https://docs.crisp.chat/guides/chatbox-sdks/android-sdk/
Other
55 stars 17 forks source link

IllegalStateException: Can not perform this action after onSaveInstanceState #74

Closed FrantisekGazo closed 1 year ago

FrantisekGazo commented 2 years ago

I found multiple exceptions like this coming from the crisp sdk.

crisp sdk version: 1.0.7

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
    at androidx.fragment.app.FragmentManager.checkStateLoss(FragmentManager.java:1691)
    at androidx.fragment.app.FragmentManager.enqueueAction(FragmentManager.java:1731)
    at androidx.fragment.app.BackStackRecord.commitInternal(BackStackRecord.java:321)
    at androidx.fragment.app.BackStackRecord.commit(BackStackRecord.java:286)
    at androidx.fragment.app.DialogFragment.dismissInternal(DialogFragment.java:276)
    at androidx.fragment.app.DialogFragment.dismiss(DialogFragment.java:228)
    at im.crisp.client.b.e.b.a.b
    at im.crisp.client.b.e.b.a.f
    at im.crisp.client.b.e.b.a$a.i
    at im.crisp.client.b.e.b.a$a.lambda$q0csS3PiIawpr6l4W4Ieecax0Lw
    at im.crisp.client.b.e.b.-$$Lambda$a$a$q0csS3PiIawpr6l4W4Ieecax0Lw.run(lambda)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6121)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
eliottvincent commented 2 years ago

Thanks! We'll check what's causing those exceptions.

nasikhunamin commented 2 years ago

I have same issue!

Doc1faux commented 2 years ago

I @FrantisekGazo & @nasikhunamin and thank you for your feedbacks. This crash has been fixed in 1.0.9. I let you reopen this issue if it happens again.

FrantisekGazo commented 2 years ago

@Doc1faux it's still happening. Currently on version 1.0.10. Please reopen this issue.

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
    at androidx.fragment.app.FragmentManager.p(FragmentManager.java:2)
    at androidx.fragment.app.FragmentManager.Z(FragmentManager.java:5)
    at f.m.d.a.s(BackStackRecord.java:12)
    at f.m.d.a.h(BackStackRecord.java:1)
    at f.m.d.d.show(DialogFragment.java:5)
    at im.crisp.client.internal.t.a.a
    at im.crisp.client.internal.t.a.a
    at im.crisp.client.internal.t.a$a.b
    at im.crisp.client.internal.t.a$a.m
    at i.a.a.b.j.e.run(lambda)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6121)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Doc1faux commented 2 years ago

Hi @FrantisekGazo and thank you for your feedback.

I firstly looked over your stacktrace but found nothing which could give me a hint on why this could happen because I've already protected all UI calls from async with isAdded() methods... But while looking for "State loss exceptions", I found an old interesting blog post about it: https://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html After reading this, I protected more these calls with the following pattern:

if (isAdded()) {
    FragmentManager manager = getParentFragmentManager() | getChildFragmentManager();
    if (! manager.isStateSaved()) {
        // perform fragment transaction
    }
}

I hope it will fix definitively these crashes... I plan it for the next release.

Doc1faux commented 1 year ago

@FrantisekGazo 1.0.13 fixing this issue has just been released. It can take a few hours before it will be available. I close the issue.

FrantisekGazo commented 1 year ago

thank you, will try