Networking 2 Flashcards
If networking operations are being performed on the UI thread, and the device is rotated, what happens to the networking result?
Application state is destroyed and rebuilt, thus the result of the networking operation is interrupted and lost.
What is the solution to the configuration changes issue when networking?
User a worker thread such as provided by an implementations of Loader.
Define what a loader is…
A framework component that provides a way to asynchronously load data to an Activity or Fragment.
Where does the worker loader thread send the result when finished?
Back to the UI thread.
What is Loader a subclass of?
AsyncTaskLoader
Give some examples of where a Loader can pull data from…
Database, Website, Content Provider.
Who is responsible for creating and destroying the Loader worker thread?
The Loader object.
What is a Cursor Loader?
A loader that specifically gets data from Content Providers.
What are the 4 steps for creating and using a Loader?
1) Implement a sub-class of Loader and override loadInBackground( ).
2) Create an instance of the Loader in an Activity or Fragment.
3) Register the Loader with the LoaderManager.
4) Implement onLoadFinished( ) to receive the data from the Loader.
Define each of the 3 Loader callback methods…
onCreateLoader( ) -> Instantiate and return a Loader.
onLoadFinished( ) -> When Loader is finished, move data to the Views.
onLoaderReset( ) -> When Loader is reset, make the data unavailable.
What are the 4 steps for implementing AsyncTaskLoader?
1) Define the Loader ID.
2) Call initLoader( ) in containers onCreate( ).
3) Create a LoadManager and call getLoadManager( ).
4) Implement the AsyncTaskLoader callback methods.
Explain the main difference between Loader and AsyncTaskLoader…
Loader has a LoaderManager which automatically Creates and Destroys Loaders. AsyncTaskLoader has to be manually Created and Destroyed.