Skip to content

java.lang.IllegalStateException: FragmentManager has been destroyed #43

@Arun-KumarWSE

Description

@Arun-KumarWSE

java.lang.IllegalStateException: FragmentManager has been destroyed
at androidx.fragment.app.FragmentManager.enqueueAction(FragmentManager.java:1896)
at androidx.fragment.app.BackStackRecord.commitInternal(BackStackRecord.java:342)
at androidx.fragment.app.DialogFragment.show(DialogFragment.java:502)
at com.formbricks.android.webview.FormbricksFragment.show(FormbricksFragment.java:...)
at com.formbricks.android.Formbricks.showSurvey(Formbricks.java:...)
at java.util.TimerThread.run(Timer.java:577)

Steps to Reproduce:

User logs in → DashboardActivity launches with HomeFragment.
User performs an action in HomeFragment that calls Formbricks.track("event_name").
App crashes immediately with FragmentManager has been destroyed.
Subsequent launches work fine; the survey displays without issues.

Root Cause:

The SDK schedules survey display asynchronously using a Timer thread. When the Timer fires, it calls DialogFragment.show() with a FragmentManager reference that may have been destroyed or detached by that time, even though the Activity and Fragment are still active. This leads to the IllegalStateException. Wrapping Formbricks.track() in try/catch, delaying execution, or running on the main thread does not prevent the crash because the exception originates inside the SDK’s Timer thread.

Impact:
App crashes for first-time login users, making the survey unsafe to display.

Suggested Fix:
Ensure DialogFragment.show() is executed on the main thread.
Validate that the FragmentManager is still valid (not destroyed or detached) before committing the fragment.
Avoid holding stale FragmentManager references across delayed background tasks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions