I have a singleInstance Activity and a Fragment which I instantiate in the onCreate() method and add into a FrameLayout container into the layout of the activity. The activity does nothing except printing out the logs. I am using the android-support-v4 lib and android 2.3.3.
I observed a strange lifecycle behavior with this setting and I wonder if you might help me to explain this. I will provide the logs for the lifecycles:
First call of the activity:
07-07 15:12:17.990 V/FragActivity( 2358): onCreate >> com.test.fragmentlife.FragActivity@44f98778
07-07 15:12:21.010 V/FragActivity( 2358): onCreate <<
07-07 15:12:21.020 V/LayoutFragment( 2358): onAttach > LayoutFragment{44f467c8 #0 id=0x7f070000}
07-07 15:12:24.021 V/LayoutFragment( 2358): onAttach <
07-07 15:12:24.021 V/LayoutFragment( 2358): onCreate > LayoutFragment{44f467c8 #0 id=0x7f070000}
07-07 15:12:27.020 V/LayoutFragment( 2358): onCreate <
07-07 15:12:27.020 V/LayoutFragment( 2358): onCreateView > LayoutFragment{44f467c8 #0 id=0x7f070000}
07-07 15:12:30.022 V/LayoutFragment( 2358): onCreateView <
07-07 15:12:30.030 V/LayoutFragment( 2358): onActivityCreated > LayoutFragment{44f467c8 #0 id=0x7f070000}
07-07 15:12:33.030 V/LayoutFragment( 2358): onActivityCreated <
07-07 15:12:33.030 V/LayoutFragment( 2358): onStart > LayoutFragment{44f467c8 #0 id=0x7f070000}
07-07 15:12:36.030 V/LayoutFragment( 2358): onStart <
07-07 15:12:36.040 V/FragActivity( 2358): onStart > com.test.fragmentlife.FragActivity@44f98778
07-07 15:12:39.041 V/FragActivity( 2358): onStart <
07-07 15:12:39.041 V/LayoutFragment( 2358): onStop > LayoutFragment{44f467c8 #0 id=0x7f070000}
07-07 15:12:42.040 V/LayoutFragment( 2358): onStop <
07-07 15:12:42.040 V/FragActivity( 2358): onResume > com.test.fragmentlife.FragActivity@44f98778
07-07 15:12:45.041 V/FragActivity( 2358): onResume <
07-07 15:12:45.041 V/LayoutFragment( 2358): onStart > LayoutFragment{44f467c8 #0 id=0x7f070000}
07-07 15:12:48.040 V/LayoutFragment( 2358): onStart <
07-07 15:12:48.040 V/LayoutFragment( 2358): onResume > LayoutFragment{44f467c8 #0 id=0x7f070000}
07-07 15:12:51.042 V/LayoutFragment( 2358): onResume <
First question: why is the onStop() method of the fragment during the creation of the activity? The Fragment displays fine on the screen.
After that I restart the activity by firing an intent, causing the onNewIntent() lidecycle method of the activity.
07-07 15:13:17.220 V/LayoutFragment( 2358): onPause > LayoutFragment{44f467c8 #0 id=0x7f070000}
07-07 15:13:20.220 V/LayoutFragment( 2358): onPause <
07-07 15:13:20.230 V/FragActivity( 2358): onPause > com.test.fragmentlife.FragActivity@44f98778
07-07 15:13:23.231 V/FragActivity( 2358): onPause <
07-07 15:13:23.231 V/FragActivity( 2358): onNewIntent > com.test.fragmentlife.FragActivity@44f98778
07-07 15:13:26.231 V/FragActivity( 2358): onNewIntent <
07-07 15:13:26.231 V/FragActivity( 2358): onResume > com.test.fragmentlife.FragActivity@44f98778
07-07 15:13:29.230 V/FragActivity( 2358): onResume <
Second question: why is the onResume() method of the fragment not called? It is still visible on the screen. As far as i know activity and lifecycle methods should go hand in hand...
After that i restart the activity a second time:
07-07 15:13:42.140 V/FragActivity( 2358): onPause > com.test.fragmentlife.FragActivity@44f98778
07-07 15:13:45.143 V/FragActivity( 2358): onPause <
07-07 15:13:45.143 V/FragActivity( 2358): onNewIntent > com.test.fragmentlife.FragActivity@44f98778
07-07 15:13:48.144 V/FragActivity( 2358): onNewIntent <
07-07 15:13:48.150 V/FragActivity( 2358): onResume > com.test.fragmentlife.FragActivity@44f98778
07-07 15:13:51.151 V/FragActivity( 2358): onResume <
Now the lifecycle methods of the fragmen are not triggered at all.. how is that?