http://developerstudyjams.com/
Week 6 - Retrospectively looking at Udacity Lesson 4c Loaders
Google Developers Study Jams is a free series of global, community-run, in-person study groups. The first Study Jams series is presented in partnership with Udacity and will follow their Android Fundamentals curriculum. Google Developer Group facilitators certified in the course will lead the Study Jams that meet once weekly for 8 - 9 weeks.
Promote using hashtag #devstudyjam
4. Prime Directive
‘Regardless of where we are up to, we
understand and truly believe that
everyone did the best job he or she
could, given his or her skills and
abilities, the personal time available,
and the situation at hand.’
5. Difficulty Check
● Who completed the class?
● How long did it take?
● Hands up 1-10 difficulty of the weeks lesson
● Any specific areas of the lesson that require
particular focus?
6. Retro lesson 4c Loaders
What we learnt last week
● Problems
● Solution with loader
● Key methods
● How loaders fit into the bigger picture
8. Problem 2
● Loading data in UI/Main thread can take time and
make UI less responsive
○ Load data in AsyncTask why don’t we?
■ On orientation change we’ll re-create
AsyncTask and consume even more resources
● Loaders registered to LoaderManager via static ID
and live beyond lifecycle of Fragment or Activity
○ Monitor source changes and deliver new data.
9. (Cursor)Loader 1
● Available from HoneyComb (3.0+)
○ Available in compatibility library
● Load data in AsyncTask on the background thread
○ provides updates to UI thread.
● CursorLoader = AsynTaskLoader for content
providers
○ Returns cursor to UI
○ Monitors changes to data and notifies UI
○ On rotation when activity reconnects to loader
its passed the last Cursor
10. (Cursor)Loader 2
● Key components
○ Loader_ID
○ Interface to implement
■ LoaderManager.LoaderCallbacks<Cursor>
○ InitLoader
■ getLoaderManager().initLoader(ID, null, this);
○ Callbacks
■ public Loader<Cursor> onCreateLoader(int loaderID, Bundle bundle) //Build Uri and create new CursorLoader
■ public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) //update adapter with new cursor
■ public void onLoaderReset(Loader<Cursor> loader) // release resources
14. What went well
● Responsive
○ Hard work off UI/Main thread
Data retrieval not tied to Activity lifecycle
Saves resources/memory
● Makes observing data easier
○ Less coding
● Updates update the UI without us doing
anything!
20. See you next week..
- Time: Tuesday 7pm
- Place: SpacePort
- Things needed: You + Questions +
Feedback
- Can contact us if issues:
@blundell_apps / @android_mcr