Paul
03/19/2021, 11:44 AMtherealbluepandabear
03/19/2021, 7:56 PMMichal Harakal
03/19/2021, 8:14 PMPaul
03/19/2021, 8:23 PMsolidogen
03/23/2021, 3:31 PMfinal override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Prevent the view from recreation until onDestroy is called
return if(isViewCreated) {
viewBinding.root
} else {
super.onCreateView(inflater, container, savedInstanceState)
}
}
Could you explain why this is wanted? Is there ever a possibility that fragment’s view will be created twice, not being destroyed beforehand?Paul
03/23/2021, 4:13 PMonDestroy
method is called.
The Fragment's view gets cleared inside onDestroy
method, which means that up until that method is called, the Fragment always returns a cached-in view inside onCreateView
. Therefore, it's not possible that Fragment's view will be created twice.
Hope it helps.solidogen
03/23/2021, 4:22 PMTrần Hữu Phúc
04/19/2021, 5:02 AMtherealbluepandabear
04/19/2021, 10:17 AMPaul
04/19/2021, 2:19 PM