0

Why would my Fragment be flapping during app startup?!?

02-10 11:41:34.699: D/SessionDetailFragment(19272): onResume() 99
02-10 11:41:34.699: D/MPQAudioFragment(19272): onResume() 00
02-10 11:41:34.699: D/MPQAudioFragment(19272): onResume() 99
02-10 11:41:34.699: D/SessionDetailFragment(19272): onPause() 00
02-10 11:41:34.699: D/MPQAudioFragment(19272): onStop() 00 bound_flag: false
02-10 11:41:34.699: D/MPQAudioFragment(19272): onStop() 05 mAudioService: null
02-10 11:41:34.699: D/SessionDetailFragment(19272): onStop() 00 bound_flag: false
02-10 11:41:34.699: D/SessionDetailFragment(19272): onStop() 05 mAudioService: null
02-10 11:41:34.709: D/SessionDetailFragment(19272): onDetach() 00
02-10 11:41:34.709: D/SessionDetailFragment(19272): onAttach() 00
02-10 11:41:34.709: D/SessionDetailFragment(19272): onAttach() 10 activity:MPQMainTabActivity

Note that as soon as SessionDetailFragment completes onResume() (as does its sub-Fragment MPQAudioFragment), they immediately run onPause()?!?! Then as soon as the fragment is torn down, it again begins the onAttach() routine?

Fortunately this flapping only seems to occur once, but it makes maintaining state a bit more challenging (and I would like to understand what is happening and why).


UPDATE:

For now, I'm working around the flapping problem by using static member attributes for key data.

This SO post points to cases where onSaveInstanceState() does not get called, and potential workarounds: https://stackoverflow.com/a/2909211/1742657

Community
  • 1
  • 1
donfede
  • 734
  • 1
  • 9
  • 25
  • even worse - `onSaveInstanceState()` does not appear to get called during this flap :( . The only 'hack'/workaround I can see is using static member variables. – donfede Feb 10 '13 at 17:22

1 Answers1

0

UPDATE/CLOSURE 2013-03-24:

The duplicate Fragments appear to be caused by a parent/wrapper TabHost, and multiple calls to updateTab methods. The first call would be from user presses of buttons and menus, and the second call would come from onTabChanged() triggered by the Listener.

Both calls would check for an existing fragment, but since instantiation had not been completed, both ended up creating a new fragment.

donfede
  • 734
  • 1
  • 9
  • 25