Subfragment Demo Project
Here is a demo project requested to showcase the error mentioned above.
In this project there are Fragment A and Fragment B, which both extends CustomFragment that extends Fragment from Jmix.
In our CustomFragment, there is a method that needs to be called onAttach, so we used the addAttachListener()
to add that in and expect it to be triggered.
All fragments have their own respective onHostAttach event as well, which is expected to trigger after the onAttach event that is stated in CustomFragment.
In Fragment A, there are 2 tabs, each with their own instance of Fragment B.
The issue right now is, the onAttach event of Fragment B from the “second” tab did not trigger until user selects the tab, only then it will trigger.
However onHostAttach events for all fragments are triggered when the parent view shows on screen.
My question is:
How come the onHostAttach event will trigger for the “unselected” tab’s Fragment B, but the onAttach event that is added through addAttachListener()
not trigger accordingly ?
Is this an expected behaviour? Or how can I achieve the results I expected, which is:
- Trigger all the attachEvents added through
addAttachListener()
in CustomFragment.
- Trigger all the onHostAttach events after that.

This is a snapshot of my logs, you should be able to get this as well when you open the SubfragmentDemoView.
Regards,
Wei Jian.