Android
Android - getSupportFragmentManager, getChildFragmentManager
jinhan38
2021. 3. 21. 14:34
It is necessary to seperate the use of 'getSupportFragmentManager()' and 'getChildFragmentManager()'.
If you have Activity "A" and Fragment "A-1" in "A", you should use getSupportFragmentManager() when you manage "A-1". getSupportFragmentManager() need activity.
But If you have Fragment "B", "C" in "A-1", you shoud use getChildFragmentManager() when you manage "B", "C".
If you work in fragment ", getChildFragmentManager() would not need activity.
For example,
activity.getSupportFragmentManager().beginTransaction()
.replace({container}, {fragment})
.commitAllowingStateLoss();
getChildFragmentManager().beginTransaction()
.replace({container}, {fragment})
.commitAllowingStateLoss();