FragNav icon indicating copy to clipboard operation
FragNav copied to clipboard

Fragment onActivityCreated & onCreateView called twice on configuration changes

Open hannta opened this issue 6 years ago • 1 comments

I use FragNav with AHBottomNavigation to implement bottom tab navigation in my app. So very basic usage of FragNav here.

I noticed that my tab fragments lifecycle methods onActivityCreated and onCreateView are called twice on configuration changes (when I e.g. rotate the phone).

This is not happening on first tab fragment. I does not matter what kind of fragments I have, first fragment is allays working as expected (lifecycle methods not called twice).

This issue is reproducing with version 2.4.0, if I downgrade to 2.2.2, everything is working fine.

hannta avatar Apr 07 '18 07:04 hannta

Still in 3.3.0

I have bottom bar and switch on some tab, say MessagesFeedFragment. All is OK. Then i skip the app on my device, terminate it (to emulate system process killing) and then reopen from Recent Apps Tray again. i can see in logcat that i have Fragment's lifecycle methods called twice.

I also supply hash code for MessagesFeedFragment instance to logs.

And what is more confusing is that i see that MessagesFeedFragment is created and attached and then destroyed and detached, and after a while the same MessagesFeedFragment (but different instance, according to hash code) is then created and attached and is then running as normal.

So, why is that first MessagesFeedFragment instance that is created-attached-destroyed-detached, being replaced with another instance of the same MessagesFeedFragment?

logs:

2019-08-29 08:43:53.819 V/MessagesFeedFragment[86663268]: onAttach
2019-08-29 08:43:53.830 V/MessagesFeedFragment[86663268]: onCreate
2019-08-29 08:43:54.973 V/MessagesFeedFragment[86663268]: onCreateView
2019-08-29 08:43:55.024 V/MessagesFeedFragment[86663268]: onViewCreated
2019-08-29 08:43:55.076 V/MessagesFeedFragment[86663268]: onActivityCreated(savedInstanceState != null)
2019-08-29 08:43:55.455 V/MessagesFeedFragment[86663268]: onDestroyView
2019-08-29 08:43:55.474 V/MessagesFeedFragment[86663268]: onDestroy
2019-08-29 08:43:55.477 V/MessagesFeedFragment[86663268]: onDetach
...
2019-08-29 08:43:55.518 V/MessagesFeedFragment[69655091]: onAttach
2019-08-29 08:43:55.520 V/MessagesFeedFragment[69655091]: onCreate
2019-08-29 08:43:55.650 V/MessagesFeedFragment[69655091]: onCreateView
2019-08-29 08:43:55.686 V/MessagesFeedFragment[69655091]: onViewCreated
2019-08-29 08:43:55.721 V/MessagesFeedFragment[69655091]: onActivityCreated(null)
2019-08-29 08:43:56.038 V/MessagesFeedFragment[69655091]: onStart
2019-08-29 08:43:56.177 V/MessagesFeedFragment[69655091]: onResume

Also note that first instance has not even started, there was no onStart() call. Maybe it's by design...

This happens when i initialize FragNav passing savedInstanceState == null as second argument to initialize(). If i pass savedInstanceState not null, then it creates single MessagesFeedFragment, passing savedInstanceState to it in onActivityCreated(), as expected.


I'm not doing anything special and use FragNav as described in README

pls clarify ^___^

orcchg avatar Aug 29 '19 06:08 orcchg