Top Banner
Lesson 4b. Content Providers and Loaders 도우미 이찬형
22

Lesson4b. Content Providers and Loaders

Jul 15, 2015

Download

Software

Chanhyeong Lee
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lesson4b. Content Providers and Loaders

Lesson����������� ������������������  4b.����������� ������������������  Content����������� ������������������  Providers����������� ������������������  and����������� ������������������  Loaders

도우미����������� ������������������  이찬형

Page 2: Lesson4b. Content Providers and Loaders

Content����������� ������������������  Providers

•bind����������� ������������������  view����������� ������������������  to����������� ������������������  data����������� ������������������  model����������� ������������������  

•URI����������� ������������������  

•CONTENT://COM.EXAMPLE.ANDROID.SUNSHINE.APP/WEATHER/85456����������� ������������������  

•CONTENT://COM.EXAMPLE.ANDROID.SUNSHINE.APP/WEATHER/85456/20140624

Page 3: Lesson4b. Content Providers and Loaders

Why����������� ������������������  Content����������� ������������������  Providers����������� ������������������  Matter

Page 4: Lesson4b. Content Providers and Loaders

Adding����������� ������������������  Content����������� ������������������  Provider����������� ������������������  to����������� ������������������  our����������� ������������������  Contract

Page 5: Lesson4b. Content Providers and Loaders

Create����������� ������������������  WeatherProvider

•extends����������� ������������������  COntentProvider����������� ������������������  

•AndroidManifest.xml����������� ������������������  

•OnCreate

Page 6: Lesson4b. Content Providers and Loaders

Coding����������� ������������������  the����������� ������������������  Content����������� ������������������  Provider����������� ������������������  :����������� ������������������  getType()

•UriMatcher����������� ������������������  

•testGetType()����������� ������������������  

•ContentResolver

Page 7: Lesson4b. Content Providers and Loaders

Coding����������� ������������������  the����������� ������������������  Content����������� ������������������  Provider����������� ������������������  :����������� ������������������  query()

•implement����������� ������������������  every����������� ������������������  cases����������� ������������������  

•setNotificationUri()

Page 8: Lesson4b. Content Providers and Loaders

Add����������� ������������������  a����������� ������������������  join����������� ������������������  query

Page 9: Lesson4b. Content Providers and Loaders

Add����������� ������������������  a����������� ������������������  join����������� ������������������  query

•SQLiteQueryBuilder����������� ������������������  

•inner����������� ������������������  join����������� ������������������  

•_ID����������� ������������������  

•http://egloos.zum.com/sweeper/v/3002133

Page 10: Lesson4b. Content Providers and Loaders

Inserting,����������� ������������������  Updating����������� ������������������  and����������� ������������������  Deleting

•match����������� ������������������  the����������� ������������������  base����������� ������������������  URI����������� ������������������  

•getContext().getContentResolver().notifyChange(uri,����������� ������������������  null);

Page 11: Lesson4b. Content Providers and Loaders

Efficient����������� ������������������  Updates����������� ������������������  :����������� ������������������  Inserts•bulkInsert����������� ������������������  

•What����������� ������������������  is����������� ������������������  transcation����������� ������������������  ?����������� ������������������  

•http://ko.wikipedia.org/wiki/%ED%8A%B8%EB%9E%9C%EC%9E%AD%EC%85%98����������� ������������������  

•beginTranscation����������� ������������������  

•endTranscation

Page 12: Lesson4b. Content Providers and Loaders

Step����������� ������������������  3.����������� ������������������  Connect����������� ������������������  to����������� ������������������  Sunshine•Step����������� ������������������  1.����������� ������������������  Create����������� ������������������  the����������� ������������������  underlying����������� ������������������  data����������� ������������������  source����������� ������������������  

•Step����������� ������������������  2.����������� ������������������  the����������� ������������������  ContentProvider����������� ������������������  class����������� ������������������  

•FethchWeatherTask����������� ������������������  use����������� ������������������  the����������� ������������������  ContentProvider����������� ������������������  

•Loader����������� ������������������  

•CursorAdapter

Page 13: Lesson4b. Content Providers and Loaders

Refactoring����������� ������������������  FetchWeatherTask

•Extract����������� ������������������  class����������� ������������������  -����������� ������������������  FetchWeatherTask����������� ������������������  

•Utility

Page 14: Lesson4b. Content Providers and Loaders

Inserts����������� ������������������  with����������� ������������������  ContentProvider

•getWeatherDataFromJson����������� ������������������  in����������� ������������������  FetchWeatherTask����������� ������������������  

•sql����������� ������������������  date����������� ������������������  vs����������� ������������������  util����������� ������������������  date����������� ������������������  

•http://javarevisited.blogspot.kr/2012/04/difference-between-javautildate-and.html

Page 15: Lesson4b. Content Providers and Loaders

Loaders����������� ������������������  are����������� ������������������  Awesome

Page 16: Lesson4b. Content Providers and Loaders

Loaders����������� ������������������  are����������� ������������������  Awesome

•async����������� ������������������  task����������� ������������������  to����������� ������������������  load����������� ������������������  data����������� ������������������  on����������� ������������������  the����������� ������������������  background����������� ������������������  thread

Page 17: Lesson4b. Content Providers and Loaders

Using����������� ������������������  Loaders����������� ������������������  in����������� ������������������  our����������� ������������������  App•onActivityCreated����������� ������������������  

•onCreateLoader����������� ������������������  

•onLoadFinished����������� ������������������  

•onLoaderReset����������� ������������������  

•mForecastAdapter.swapCursor(null);

Page 18: Lesson4b. Content Providers and Loaders

SimpleCursorAdapter•Change����������� ������������������  the����������� ������������������  type����������� ������������������  of����������� ������������������  the����������� ������������������  mForecastAdapter����������� ������������������  to����������� ������������������  SimpleCursorAdapter����������� ������������������  

•https://github.com/udacity/Sunshine/compare/4.34-split-forecast-textviews...4.35-simple-cursor-adapter

Page 19: Lesson4b. Content Providers and Loaders

Implement����������� ������������������  Details

•https://github.com/udacity/Sunshine/compare/4.37-user-settings-change...4.38-implement-details-cursor-loader

Page 20: Lesson4b. Content Providers and Loaders

Step����������� ������������������  3.����������� ������������������  Final����������� ������������������  Summary

Page 21: Lesson4b. Content Providers and Loaders

Storing����������� ������������������  Images����������� ������������������  or����������� ������������������  Binary����������� ������������������  Data

Page 22: Lesson4b. Content Providers and Loaders

Making����������� ������������������  your����������� ������������������  COntentProvider����������� ������������������  Accessible