1

I have an activity with a Fragment

<FrameLayout android:id="@+id/list_fragment"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1" />

at onCreate i set some content for the first time

fm = getSupportFragmentManager();
fm.beginTransaction().add(R.id.list_fragment, mListFragment).commit();

When i now rotate my device the onCreate of my activity is called and while doing

 super.onCreate(savedInstanceState);

the onCreate of my fragment is called, too. And now

fm.findFragmentById(R.id.list_fragment); 

is not null, unlike on the first call of onCreate(), although an other layout-xml-file is used the old fragment is in place in the new view.

Does android automatically search for views with the same id in the new layout and puts the fragments into them?

Edit:

When i change the id in the second layout, it seems not to work anymore (no exception, but an empty screen) which confirms my assumption

EDIT 2

it seems that this is the answer to my question, but couldn't find the information in google docs

https://stackoverflow.com/a/16946870/1131857

can anybody explain how exactly android does that?

Community
  • 1
  • 1
wutzebaer
  • 14,365
  • 19
  • 99
  • 170

0 Answers0