Call To Fragment Life Cycle Methods Increases With Every Orientation Change
Orientation change from one fragment to another. Orientation 1 (Landscape to Portrait): onSaveInstanceState() of fragment 1. onSaveInstanceState() of fragment 2. onStop() of fragm
Solution 1:
Probable cause to your Lifecycle might be, not handling Fragment BackStack correctly. That's why it might be calling multiple times. I too have faced this issues with fragments. But for now you can remove adding your Fragment to backStack to proceed.
You code would become:
Fragment1firstFragment=newFragment1();
Bundlebundle=newBundle();
firstFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction()
.replace(R.id.article_fragment, firstFragment)
.commit();
Some examples where you can find handling AddingBackStack to a Fragment can be found at:http://www.javacodegeeks.com/2013/06/android-fragment-transaction-fragmentmanager-and-backstack.html
http://www.vogella.com/tutorials/AndroidFragments/article.html
And In order to retain the Fragments member values, you can use SharedPreference in Android to hold values and retrieve when activity is loaded. http://developer.android.com/reference/android/content/SharedPreferences.html
Post a Comment for "Call To Fragment Life Cycle Methods Increases With Every Orientation Change"