Lesson 4a. Lifecycle and Database 도우미 이찬형
Lesson����������� ������������������ 4a.����������� ������������������ Lifecycle����������� ������������������ and����������� ������������������ Database
도우미����������� ������������������ 이찬형
Introduction
•Provides����������� ������������������ a����������� ������������������ seamless����������� ������������������
•When����������� ������������������ networks����������� ������������������ may����������� ������������������ be����������� ������������������ slow����������� ������������������ or����������� ������������������ unavailable
Why����������� ������������������ We����������� ������������������ need����������� ������������������ an����������� ������������������ Activity����������� ������������������ Lifecycle
•Resources����������� ������������������ are����������� ������������������ extremely����������� ������������������ limited����������� ������������������
•Kills����������� ������������������ low����������� ������������������ priority����������� ������������������ applications����������� ������������������ at����������� ������������������ any����������� ������������������ time����������� ������������������
The����������� ������������������ Android����������� ������������������ Activity����������� ������������������ LifeCycle
Active����������� ������������������ and����������� ������������������ Visible����������� ������������������ Lifetime
Lifecycle����������� ������������������ Events•What����������� ������������������ is����������� ������������������ the����������� ������������������ sequence����������� ������������������ of����������� ������������������ lifecycle����������� ������������������ events����������� ������������������ following����������� ������������������ a����������� ������������������ device����������� ������������������ rotation?����������� ������������������
•onPause����������� ������������������
•onStop����������� ������������������
•onCreate����������� ������������������
•onResume����������� ������������������
•onStart����������� ������������������
•onDestroy
How����������� ������������������ to����������� ������������������ prepare����������� ������������������ for����������� ������������������ Termination
•OnPause/OnStop����������� ������������������
•Sensor����������� ������������������ Listeners����������� ������������������
•Location����������� ������������������ updates����������� ������������������
•Dynamic����������� ������������������ Broadcast����������� ������������������ Receivers����������� ������������������
•Game����������� ������������������ Physics����������� ������������������ Engine
Maintaining����������� ������������������ State
•get����������� ������������������ wrong����������� ������������������ if����������� ������������������ you����������� ������������������ don’t����������� ������������������ understand
Good����������� ������������������ Android����������� ������������������ Citizen
•minimizing����������� ������������������ network����������� ������������������
•works����������� ������������������ seamlessly����������� ������������������ between����������� ������������������ offline����������� ������������������ and����������� ������������������ online����������� ������������������
•creating����������� ������������������ a����������� ������������������ cache
Storing����������� ������������������ Data����������� ������������������ in����������� ������������������ android
•network����������� ������������������
•shared����������� ������������������ Preperences����������� ������������������
•SQLite����������� ������������������ Database
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);
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;
Optional����������� ������������������ SQLite(update,����������� ������������������ delete)
UPDATE����������� ������������������ weather����������� ������������������ ����������� ������������������
SET����������� ������������������ min����������� ������������������ =����������� ������������������ 0,����������� ������������������ max����������� ������������������ =����������� ������������������ 100����������� ������������������ ����������� ������������������
where����������� ������������������ date����������� ������������������ >=����������� ������������������ 20140626����������� ������������������ AND����������� ������������������ date����������� ������������������ <=����������� ������������������ 20140627;����������� ������������������
!
DELETE����������� ������������������ FROM����������� ������������������ weather����������� ������������������ WHERE����������� ������������������ humidity����������� ������������������ !=����������� ������������������ 0;
Optional����������� ������������������ SQLite(alter,����������� ������������������ drop)
ALTER����������� ������������������ TABLE����������� ������������������ weather����������� ������������������ ����������� ������������������
ADD����������� ������������������ COLUMN����������� ������������������ description����������� ������������������ ����������� ������������������
TEXT����������� ������������������ NOT����������� ������������������ NULL����������� ������������������ ����������� ������������������
DEFAULT����������� ������������������ 'Sunny';����������� ������������������
!
DROP����������� ������������������ TABLE����������� ������������������ weather;
SQLite����������� ������������������ Databases
Sunshine����������� ������������������ Github����������� ������������������ Repository
•https://github.com/udacity/Sunshine
Content����������� ������������������ Providers����������� ������������������ Overview����������� ������������������ &����������� ������������������ Next����������� ������������������ Steps
Step����������� ������������������ 1.����������� ������������������ Create����������� ������������������ Underlying����������� ������������������ Data����������� ������������������ Source
•Contract����������� ������������������ class����������� ������������������
•SQLiteOpenHelper����������� ������������������ class����������� ������������������
•test����������� ������������������ code
Final����������� ������������������ Detail����������� ������������������ Wireframe
Weather����������� ������������������ Contract
•BaseColumns����������� ������������������
•Location����������� ������������������ info����������� ������������������
•forecast����������� ������������������ data����������� ������������������
•foreign����������� ������������������ key
Create����������� ������������������ Databases����������� ������������������ with����������� ������������������ SQLiteOpenHelper
•weather����������� ������������������ table����������� ������������������ Create����������� ������������������ 문����������� ������������������ 분석����������� ������������������
•SQLiteOpenHelper����������� ������������������ onUpdate()����������� ������������������ method
JUnit����������� ������������������ testing
•Cursor����������� ������������������
•Refactoring
Step2.����������� ������������������ Create����������� ������������������ the����������� ������������������ ContentProvider