fragment run before fragmentActivity
android, android-fragments
Solution
In simple, this is `life cycle` log for fragment within activity,
05-20 10:54:22.014: I/ActivityAndFragmentLifeCycle.java(6211): onCreate() Before setContentView()
05-20 10:54:22.054: V/TestingFragment.java(6211): onAttach()
05-20 10:54:22.054: V/TestingFragment.java(6211): onCreate()
05-20 10:54:22.054: V/TestingFragment.java(6211): onCreateView()
05-20 10:54:22.054: I/ActivityAndFragmentLifeCycle.java(6211): onCreate() After setContentView()
05-20 10:54:22.064: V/TestingFragment.java(6211): onActivityCreated()
05-20 10:54:22.064: V/TestingFragment.java(6211): onStart()
05-20 10:54:22.064: I/ActivityAndFragmentLifeCycle.java(6211): onStart()
05-20 10:54:22.064: I/ActivityAndFragmentLifeCycle.java(6211): onResume()
05-20 10:54:22.064: V/TestingFragment.java(6211): onResume()
05-20 10:54:22.074: V/TestingFragment.java(6211): onPause()
05-20 10:54:22.074: I/ActivityAndFragmentLifeCycle.java(6211): onPause()
Here, `Activity's onCreate()` first get called. The main work of `onCreate()` is to inflate view. For that `setContentView()` get calling. At that time `Fragment's onCreateView()` get called.
`ActivityAndFragmentLifeCycle.java` extends with `FragmentActivity` and `TestingFragment.java` ectends with `Fragment`
Finally, if your activity variables value want to be alive within your fragment means you need to initialize those before `setContentView()` of your `FragmentActivity` or you need to go with programmatic fragment attachment.
Problem
There is `Fragment` which uses some values from main `FragmentActivity`. The `Fragment` is added statically (XML) and run before the main `FragmentActivity`. Is there a way to fix a run order of `Fragments` (excluding dynamic style)? There is a rule: If the `Fragment` should always be in the Activity, use XML to statically add but if it's more complex use the Java-based approach. My `Fragment` is always in Activity. However, `FragmentActivity` have to received common values/variables before fragment run. Is dynamic style is only my way?