KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a very weird issue with fragments. I use the newest support library. I also use similar code as is used by Google in their IOSCHED project But I have problem with recreating of activity after rotation. After an activity is destroyed and created again, I call methods for managing the fragment transaction (in onStart method). This line is called only once, but it creates the fragment TWICE ! This is my activity method: public abstract class SinglePaneActivity extends FragmentActivity { @Override protected void onStart() { super.onStart(); if(mFragment == null) { mFragment = onCreatePane(); mFragment.setArguments(Utils.intentToFragmentArguments(getIntent())); Log.w(TAG, "Fragment creation counter = " + createCounter); createCounter++; getSupportFragmentManager() .beginTransaction() .add(R.id.root_container,mFragment) .commit(); } } @Override protected void onStop() { Log.i(TAG, "onStop"); if(mFragment != null) { getSupportFragmentManager() .beginTransaction() .remove(mFragment) .commit(); mFragment = null; } super.onStop(); } } and my logs: --Start of application-- 11-18 13:26:37.050: I/SinglePaneActivity(19040): onCreate 11-18 13:26:37.050: I/SinglePaneActivity(19040): onStart 11-18 13:26:37.055: W/SinglePaneActivity(19040): replacing fragment, counter = 1 11-18 13:26:37.075: I/MyFragment(19040): onCreate 11-18 13:26:37.110: I/MyFragment(19040): onActivityCreated --Rotating the device-- 11-18 13:26:39.600: I/SinglePaneActivity(19040): onStop 11-18 13:26:39.600: I/SinglePaneActivity(19040): onDe
Tags (comma-separated)
Save Edits
Cancel