android jam - loaders - udacity lesson 4c
TRANSCRIPT
Android ManchesterWeek 6 - Loaders
Overview
● Sponsors message - Novoda● Retro
○ Lesson 4c Loaders● Looking Forward
○ Lesson 5 Rich and Responsive layouts● Stickers + Booklets● Questionnaire● Next Tue 7-8pm SpacePortX
Energizer
Stand up and introduce yourself to somebody around you, you don’t know
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.’
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?
Retro lesson 4c Loaders
What we learnt last week● Problems ● Solution with loader● Key methods● How loaders fit into the bigger picture
Problems 1
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.
(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
(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
Without loaders
With Loaders
What went well
What went well
● Responsive○ Hard work off UI/Main thread
Data retrieval not tied to Activity lifecycleSaves resources/memory
● Makes observing data easier○ Less coding
● Updates update the UI without us doing anything!
What didn’t go so well
What didn’t go so well
● More coding○ Time consuming
● Loaders are crayzay! initLoader() vs restartLoader() ?!?
Q&APlease pleassssse... fill in sruvey http://goo.gl/JHulAu
Next Week - Android Jam
Rich Layouts (location: Store room)
Next Lesson - Rich Layouts
Learning Objectives:- Screen densities- Fragments- Orientation change - preserving data- 2 pane layout- ActionBar- Custom Views
See you next week..
- Time: Tuesday 7pm - Place: SpacePort- Things needed: You + Questions +
Feedback- Can contact us if issues:
@blundell_apps / @android_mcr
Go forth and discuss