Top Banner
Lesson 4a. Lifecycle and Database 도우미 이찬형
23

Lesson 4a. Lifecycle and Databases

Jul 24, 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: Lesson 4a. Lifecycle and Databases

Lesson����������� ������������������  4a.����������� ������������������  Lifecycle����������� ������������������  and����������� ������������������  Database

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

Page 2: Lesson 4a. Lifecycle and Databases

Introduction

•Provides����������� ������������������  a����������� ������������������  seamless����������� ������������������  

•When����������� ������������������  networks����������� ������������������  may����������� ������������������  be����������� ������������������  slow����������� ������������������  or����������� ������������������  unavailable

Page 3: Lesson 4a. Lifecycle and Databases

Why����������� ������������������  We����������� ������������������  need����������� ������������������  an����������� ������������������  Activity����������� ������������������  Lifecycle

•Resources����������� ������������������  are����������� ������������������  extremely����������� ������������������  limited����������� ������������������  

•Kills����������� ������������������  low����������� ������������������  priority����������� ������������������  applications����������� ������������������  at����������� ������������������  any����������� ������������������  time����������� ������������������  

Page 4: Lesson 4a. Lifecycle and Databases

The����������� ������������������  Android����������� ������������������  Activity����������� ������������������  LifeCycle

Page 5: Lesson 4a. Lifecycle and Databases

Active����������� ������������������  and����������� ������������������  Visible����������� ������������������  Lifetime

Page 6: Lesson 4a. Lifecycle and Databases

Lifecycle����������� ������������������  Events•What����������� ������������������  is����������� ������������������  the����������� ������������������  sequence����������� ������������������  of����������� ������������������  lifecycle����������� ������������������  events����������� ������������������  following����������� ������������������  a����������� ������������������  device����������� ������������������  rotation?����������� ������������������  

•onPause����������� ������������������  

•onStop����������� ������������������  

•onCreate����������� ������������������  

•onResume����������� ������������������  

•onStart����������� ������������������  

•onDestroy

Page 7: Lesson 4a. Lifecycle and Databases

How����������� ������������������  to����������� ������������������  prepare����������� ������������������  for����������� ������������������  Termination

•OnPause/OnStop����������� ������������������  

•Sensor����������� ������������������  Listeners����������� ������������������  

•Location����������� ������������������  updates����������� ������������������  

•Dynamic����������� ������������������  Broadcast����������� ������������������  Receivers����������� ������������������  

•Game����������� ������������������  Physics����������� ������������������  Engine

Page 8: Lesson 4a. Lifecycle and Databases

Maintaining����������� ������������������  State

•get����������� ������������������  wrong����������� ������������������  if����������� ������������������  you����������� ������������������  don’t����������� ������������������  understand

Page 9: Lesson 4a. Lifecycle and Databases

Good����������� ������������������  Android����������� ������������������  Citizen

•minimizing����������� ������������������  network����������� ������������������  

•works����������� ������������������  seamlessly����������� ������������������  between����������� ������������������  offline����������� ������������������  and����������� ������������������  online����������� ������������������  

•creating����������� ������������������  a����������� ������������������  cache

Page 10: Lesson 4a. Lifecycle and Databases

Storing����������� ������������������  Data����������� ������������������  in����������� ������������������  android

•network����������� ������������������  

•shared����������� ������������������  Preperences����������� ������������������  

•SQLite����������� ������������������  Database

Page 11: Lesson 4a. Lifecycle and Databases

Optional����������� ������������������  SQLite(create)CREATE����������� ������������������  TABLE����������� ������������������  weather(����������� ������������������  ����������� ������������������  

_id����������� ������������������  INTEGER����������� ������������������  PRIMARY����������� ������������������  KEY,����������� ������������������  ����������� ������������������  

date����������� ������������������  TEXT����������� ������������������  NOT����������� ������������������  NULL,����������� ������������������  ����������� ������������������  

min����������� ������������������  REAL����������� ������������������  NOT����������� ������������������  NULL,����������� ������������������  ����������� ������������������  

max����������� ������������������  REAL����������� ������������������  NOT����������� ������������������  NULL,����������� ������������������  ����������� ������������������  

humidity����������� ������������������  REAL����������� ������������������  NOT����������� ������������������  NULL,����������� ������������������  ����������� ������������������  

pressure����������� ������������������  REAL����������� ������������������  NOT����������� ������������������  NULL);

Page 12: Lesson 4a. Lifecycle and Databases

Optional����������� ������������������  SQLite(insert,����������� ������������������  select)

INSERT����������� ������������������  INTO����������� ������������������  weather����������� ������������������  ����������� ������������������  

VALUES(1,’20140625',16,20,0,1029);����������� ������������������  

!

_id,����������� ������������������  date,����������� ������������������  min,����������� ������������������  max,����������� ������������������  humidity,����������� ������������������  pressure����������� ������������������  

!

SELECT����������� ������������������  *����������� ������������������  FROM����������� ������������������  weather����������� ������������������  WHERE����������� ������������������  date����������� ������������������  ==����������� ������������������  20140626;

Page 13: Lesson 4a. Lifecycle and Databases

Optional����������� ������������������  SQLite(update,����������� ������������������  delete)

UPDATE����������� ������������������  weather����������� ������������������  ����������� ������������������  

SET����������� ������������������  min����������� ������������������  =����������� ������������������  0,����������� ������������������  max����������� ������������������  =����������� ������������������  100����������� ������������������  ����������� ������������������  

where����������� ������������������  date����������� ������������������  >=����������� ������������������  20140626����������� ������������������  AND����������� ������������������  date����������� ������������������  <=����������� ������������������  20140627;����������� ������������������  

!

DELETE����������� ������������������  FROM����������� ������������������  weather����������� ������������������  WHERE����������� ������������������  humidity����������� ������������������  !=����������� ������������������  0;

Page 14: Lesson 4a. Lifecycle and Databases

Optional����������� ������������������  SQLite(alter,����������� ������������������  drop)

ALTER����������� ������������������  TABLE����������� ������������������  weather����������� ������������������  ����������� ������������������  

ADD����������� ������������������  COLUMN����������� ������������������  description����������� ������������������  ����������� ������������������  

TEXT����������� ������������������  NOT����������� ������������������  NULL����������� ������������������  ����������� ������������������  

DEFAULT����������� ������������������  'Sunny';����������� ������������������  

!

DROP����������� ������������������  TABLE����������� ������������������  weather;

Page 15: Lesson 4a. Lifecycle and Databases

SQLite����������� ������������������  Databases

Page 16: Lesson 4a. Lifecycle and Databases

Sunshine����������� ������������������  Github����������� ������������������  Repository

•https://github.com/udacity/Sunshine

Page 17: Lesson 4a. Lifecycle and Databases

Content����������� ������������������  Providers����������� ������������������  Overview����������� ������������������  &����������� ������������������  Next����������� ������������������  Steps

Page 18: Lesson 4a. Lifecycle and Databases

Step����������� ������������������  1.����������� ������������������  Create����������� ������������������  Underlying����������� ������������������  Data����������� ������������������  Source

•Contract����������� ������������������  class����������� ������������������  

•SQLiteOpenHelper����������� ������������������  class����������� ������������������  

•test����������� ������������������  code

Page 19: Lesson 4a. Lifecycle and Databases

Final����������� ������������������  Detail����������� ������������������  Wireframe

Page 20: Lesson 4a. Lifecycle and Databases

Weather����������� ������������������  Contract

•BaseColumns����������� ������������������  

•Location����������� ������������������  info����������� ������������������  

•forecast����������� ������������������  data����������� ������������������  

•foreign����������� ������������������  key

Page 21: Lesson 4a. Lifecycle and Databases

Create����������� ������������������  Databases����������� ������������������  with����������� ������������������  SQLiteOpenHelper

•weather����������� ������������������  table����������� ������������������  Create����������� ������������������  문����������� ������������������  분석����������� ������������������  

•SQLiteOpenHelper����������� ������������������  onUpdate()����������� ������������������  method

Page 22: Lesson 4a. Lifecycle and Databases

JUnit����������� ������������������  testing

•Cursor����������� ������������������  

•Refactoring

Page 23: Lesson 4a. Lifecycle and Databases

Step2.����������� ������������������  Create����������� ������������������  the����������� ������������������  ContentProvider