setupAdapter


#1

I am wondering why function setupAdapter() has been called two times in PhotoGalleryFragment.java? The first time was called in Listing. 26.13 and later it then was called in Listing 26.14. As explained in the text, onPostExecute() is run on the main thread. Why setupAdapter() was called by onCreatView() again?

Could anyone can help to explain. Thanks.


#2

The other call inside onCreateView() is used after rotation. PhotoGalleryFragment is retained, which means that onCreate() won’t be called after rotation - only onCreateView() will. The already-downloaded dataset will need to be hooked up to the GridView, which is why setupAdapter is called again.

This is why setupAdapter() is written the way it is - setupAdapter() can setup the adapter appropriately whether the data has been downloaded or not.