Skip to content

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

Comment on lines 32 to 36
* // Old (will crash):
* val fragment = IterableEmbeddedView(viewType, message, config)
*
* // New (production-ready):
* val fragment = IterableEmbeddedView.newInstance(viewType, message, config)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will crash and new production ready can be changed with more subtle professional tone.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow a dedicated class for arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that was a lot of variables and it really clustered the fragment, let me know if it is ok

Copy link
Member

@Ayyanchira Ayyanchira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Added a nit pick

Copy link
Member

@Ayyanchira Ayyanchira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@franco-zalamena-iterable franco-zalamena-iterable merged commit 6ba5719 into master Feb 10, 2026
9 of 14 checks passed
@franco-zalamena-iterable franco-zalamena-iterable deleted the fix-embedded-crash branch February 10, 2026 17:25
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

2 participants