android jam - loaders - udacity lesson 4c

21
Android Manchester Week 6 - Loaders

Upload: paul-blundell

Post on 16-Jul-2015

294 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Android Jam - Loaders - Udacity Lesson 4c

Android ManchesterWeek 6 - Loaders

Page 2: Android Jam - Loaders - Udacity Lesson 4c

Overview

● Sponsors message - Novoda● Retro

○ Lesson 4c Loaders● Looking Forward

○ Lesson 5 Rich and Responsive layouts● Stickers + Booklets● Questionnaire● Next Tue 7-8pm SpacePortX

Page 3: Android Jam - Loaders - Udacity Lesson 4c

Energizer

Stand up and introduce yourself to somebody around you, you don’t know

Page 4: Android Jam - Loaders - Udacity Lesson 4c

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.’

Page 5: Android Jam - Loaders - Udacity Lesson 4c

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?

Page 6: Android Jam - Loaders - Udacity Lesson 4c

Retro lesson 4c Loaders

What we learnt last week● Problems ● Solution with loader● Key methods● How loaders fit into the bigger picture

Page 7: Android Jam - Loaders - Udacity Lesson 4c

Problems 1

Page 8: Android Jam - Loaders - Udacity Lesson 4c

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.

Page 9: Android Jam - Loaders - Udacity Lesson 4c

(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

Page 10: Android Jam - Loaders - Udacity Lesson 4c

(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

Page 11: Android Jam - Loaders - Udacity Lesson 4c

Without loaders

Page 12: Android Jam - Loaders - Udacity Lesson 4c

With Loaders

Page 13: Android Jam - Loaders - Udacity Lesson 4c

What went well

Page 14: Android Jam - Loaders - Udacity Lesson 4c

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!

Page 15: Android Jam - Loaders - Udacity Lesson 4c

What didn’t go so well

Page 16: Android Jam - Loaders - Udacity Lesson 4c

What didn’t go so well

● More coding○ Time consuming

● Loaders are crayzay! initLoader() vs restartLoader() ?!?

Page 17: Android Jam - Loaders - Udacity Lesson 4c

Q&APlease pleassssse... fill in sruvey http://goo.gl/JHulAu

Page 18: Android Jam - Loaders - Udacity Lesson 4c

Next Week - Android Jam

Rich Layouts (location: Store room)

Page 19: Android Jam - Loaders - Udacity Lesson 4c

Next Lesson - Rich Layouts

Learning Objectives:- Screen densities- Fragments- Orientation change - preserving data- 2 pane layout- ActionBar- Custom Views

Page 20: Android Jam - Loaders - Udacity Lesson 4c

See you next week..

- Time: Tuesday 7pm - Place: SpacePort- Things needed: You + Questions +

Feedback- Can contact us if issues:

@blundell_apps / @android_mcr

Page 21: Android Jam - Loaders - Udacity Lesson 4c

Go forth and discuss