Whether updateUI() should be used in both onResume() and onCreateView() method

#1

Hi,

In Section Reloading the List, Listing 10.9 Reloading the list in onResume(), updateUI() is copied to the overridden onResume() from onCreateView().

In my opinion, the replicated updateUI() in onCreateView() is redundant. updateUI() should be moved instead of being copied to the onResume().

Any other opinion?

Thanks
BR/CrystalDf

#2

Hi, I have an opinion. Lifecycle of fragment said that the system calls this when it’s time for the fragment to draw its user interface for the first time in onCreateView() or onAttach(), onCreate(). So, the replicated updateUI() in onCreateView() is not redundant.Also, app will be pausing in the onPause() section.But, this is not saying that the user might not come back.updateUI() must be work in onResume() when user come back.

#3

Hi lscodex,

Thank you for your quick response.

I have no question that updateUI() should be used in onResume() method.
However, onResume() will be called during the first time to draw the fragment as well as onCreateView(). We can also use it to update UI, right? i.e. updateUI() in the onCreateView() is redundant.

Please let me know if I miss something. Thanks.

I paste an Activity and Fragment Lifecycle diagram to make it clear.

#4

yep.You are right. I did some test on CrimeListFragment. updateUI() in the onCreateView() is redundant.

#5

Thank you. :grinning: