Skip to content

Fix for Fragment having constructor with parameters.#986

Open
franco-zalamena-iterable wants to merge 1 commit intomasterfrom
fix-embedded-crash
Open

Fix for Fragment having constructor with parameters.#986
franco-zalamena-iterable wants to merge 1 commit intomasterfrom
fix-embedded-crash

Conversation

@franco-zalamena-iterable
Copy link
Contributor

@franco-zalamena-iterable franco-zalamena-iterable commented Feb 6, 2026

🔹 Jira Ticket(s) if any

✏️ Description

Root Cause

The IterableEmbeddedView fragment was using a constructor with parameters, which violates Android's Fragment lifecycle requirements. This causes crashes when the Android system attempts to recreate the fragment.

Why This Happens

According to the official Android documentation:

"All subclasses of Fragment must include a public no-argument constructor. The framework will often re-instantiate a fragment class when needed, in particular during state restore, and needs to be able to find this constructor to instantiate it."

Android Developers: Fragment Documentation

When Android recreates fragments (during configuration changes, process death, or back stack operations), it uses reflection to call the empty constructor only. Any parameters passed through a custom constructor are lost, leaving properties uninitialized and causing crashes.

Official Android Best Practices

From the Android documentation on Creating a Fragment:

"It is strongly recommended that subclasses do not have other constructors with parameters, since these constructors will not be called when the fragment is re-instantiated."

The Fix

Refactored IterableEmbeddedView to have newInstance with parameters and then bundle them up.
Deprecating the fragment with arguments instead of making everything nullable, this way the variables better represent what is actually there.
The deprecation makes clients swap to the newInstance, but they can do with 1 click

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IterableEmbeddedView has no empty public constructor

1 participant