You are on page 1of 58

I HC NNG

TRNG I HC BCH KHOA

KHOA CNG NGH THNG TIN


Tel. (84-511) 3736 949, Fax. (84-511) 842 771
Website: itf.ud.edu.vn, E-mail: cntt@edu.ud.vn

LUN VN TT NGHIP K S
NGNH CNG NGH THNG TIN
M NGNH : 05115

TI :
XY DNG NG DNG M THC THNH TRN
NN TNG ANDROID
M s : 11TLT - 089
Ngy bo v : 15-16/06/2013

SINH VIN : HA BCH TRUNG


LP
: 11TLT
CBHD
: TH.S L TH M HNH

NNG, 06/2013

LI CM N
Em xin chn thnh cm n cc Thy C trong khoa Cng Ngh Thng
Tin, trng i Hc Bch Khoa i Hc Nng truyn t nhng
kin thc qu bu cho em trong nhng nm em theo hc ti trng v nht
l to iu kin thun li cho em hc tp v thc hin ti tt nghip ny.
t bit, em xin chn thnh cm n c L Th M Hnh, thuc b mn
Cng Ngh Phn Mm, ngnh Cng Ngh Thng Tin, trng i Hc Bch
Khoa. Ngi trc tip, tn tnh hng dn, ng vin v gip em
trong sut thi gian thc hin ti.
c c kt qu nh ngy hm nay, em rt bit n ng B, Cha M
v nhng ngi thn trong gia nh ng vin, khch l v to mi iu
kin thun li nht v vt cht ln tinh thn trong sut qu trnh hc tp
cng nh qu trnh thc hin ti tt nghip ny.
Mc d c gng hon thnh n trong phm vi v kh nng cho
php nhng chc chn kh trnh khi nhng thiu st. Do , em rt mong
nhn c s thng cm v gp bo tn tnh ca Qu Thy C v cc
bn.
Mt ln na, em xin chn thnh cm n!

Nng, ngy . thng 06 nm 2013


Sinh vin thc hin

Ha Bch Trung

NHN XT CA CN B HNG DN
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................

Nng, ngy . thng 06 nm 2013


Cn b hng dn

Th.S L Th M Hnh

LI CAM OAN
Em xin cam oan :
1 Nhng ni dung trong lun vn ny l do em thc hin di s
hng dn trc tip ca C Th.S L Th M Hnh
2 Mi tham kho dng trong lun vn ny u c trch dn r rng
tn tc gi, tn cng trnh, thi gian, a im cng b.
3 Mi sao chp khng hp l, vi phm quy ch o to, hay gian tr,
em xin chu hon ton trch nhim.
Sinh vin,

MC LC
M U ...........................................................................................................1
I. Bi cnh ca ti ..................................................................................................... 1
II.
Mc ch v ngha ca ti .............................................................................. 1
II.1. Mc ch ca ti........................................................................................ 1
II.2. ngha ca ti .......................................................................................... 1
III.
Nhim v ca ti ............................................................................................... 2
IV.
Ni dung nghin cu ............................................................................................. 2

C S L THUYT .......................................................................................3
I.

II.

III.

IV.
V.
VI.

H iu hnh Android ................................................................................................ 3


I.1.
Lch s ca Android ...................................................................................... 3
I.2.
Kin trc ca Android ................................................................................... 4
I.2.1.
Tng ng dng ........................................................................................... 4
I.2.2.
Application framework .............................................................................. 4
I.2.3.
Library ....................................................................................................... 5
I.2.4.
Android Runtime ........................................................................................ 6
I.2.5.
Linux Kernel .............................................................................................. 6
I.3.
Android Emulator .......................................................................................... 6
I.4.
Cc thnh phn ca mt ng dng Android .................................................. 7
I.5.
Cu trc mt Project .................................................................................... 10
Cng c to mt ng dng Android ............................................................... 10
II.1. Eclipse IDE .................................................................................................. 10
II.2. Android SDK ............................................................................................... 11
Cc thnh phn giao din trong Android ............................................................. 11
III.1. View ............................................................................................................ 11
III.2. ViewGroup .................................................................................................. 12
III.2.1. LinearLayout ........................................................................................... 12
III.2.2. FrameLayout ........................................................................................... 13
III.2.3. AbsoluteLayout ........................................................................................ 13
III.2.4. RetaliveLayout ......................................................................................... 14
III.2.5. TableLayout ............................................................................................. 14
III.3. Button .......................................................................................................... 15
III.4. ImageButton ................................................................................................ 16
III.5. ImageView .................................................................................................. 16
III.6. ListView ...................................................................................................... 17
III.7. TextView ..................................................................................................... 18
III.8. EditText ....................................................................................................... 18
III.9. CheckBox .................................................................................................... 19
III.10.
Acvivity & Intend .................................................................................... 19
III.10.1.
Activity ................................................................................................. 19
III.10.2.
Intent .................................................................................................... 20
SQLite.................................................................................................................. 22
GPS ...................................................................................................................... 23
Google Map ......................................................................................................... 23

PHN TCH THIT K H THNG ........................................................24


Phn tch yu cu ..................................................................................................... 24
I.1.
c t bi ton ............................................................................................. 24
I.2.
Cc chc nng chnh ca h thng .............................................................. 24
I.2.1.
ng b facebook .................................................................................... 24
I.2.2.
Tm kim qun n .................................................................................... 24
I.2.3.
Xem thng tin qun n ............................................................................. 24
I.2.4.
Qun n a thch ..................................................................................... 24
I.2.5.
Ch ng qun n .................................................................................. 25
I.2.6.
Bn qun n ........................................................................................ 25
I.2.7.
Hc nu n .............................................................................................. 25
II.
Cc biu h thng ........................................................................................... 26
II.1. Biu ca s dng ...................................................................................... 26
II.1.1.
Biu ca s dng tng qut .................................................................. 26
II.1.2.
Xem qun n ............................................................................................ 27
II.1.3.
ng b facebook .................................................................................... 28
II.1.4.
Xem bn .............................................................................................. 28
II.1.5.
Hc nu n .............................................................................................. 29
II.2. Biu hot ng ........................................................................................ 30
II.2.1.
Tm kim .................................................................................................. 30
II.2.2.
Bn ...................................................................................................... 31
II.2.3.
Tm ng................................................................................................ 32
II.2.4.
ng nhp facebook ................................................................................ 33
II.2.5.
Xem thng tin qun n ............................................................................. 34
II.3. Biu tun t ............................................................................................ 35
II.3.1.
Tm kim .................................................................................................. 35
II.3.2.
Bn ...................................................................................................... 36
II.3.3.
Tm ng................................................................................................ 37
II.3.4.
ng nhp facebook ................................................................................ 38
III.
C s d liu sqlite .............................................................................................. 39
III.1. Bng tblATDT ............................................................................................. 39
III.2. Bng tblNauAn ............................................................................................ 39
I.

TRIN KHAI V NH GI KT QU..................................................40


I. Hng dn ci t .................................................................................................... 40
II.
Minh ha chy chng trnh................................................................................ 40

KT LUN .....................................................................................................47
I. Kt qu t c ...................................................................................................... 47
II.
nh gi kt qu .................................................................................................. 47
III.
Hng pht trin .................................................................................................. 47

DANH MC HNH NH
Hnh 11: Cu trc h thng Android ...................................................................................... 4
Hnh 12: Android emulator .................................................................................................... 7
Hnh 13: Vng i ca Activity ............................................................................................. 8
Hnh 14: Cu trc mt giao din ng dng Android ............................................................ 12
Hnh 15: B tr cc widget s dng LinearLayout ............................................................... 13
Hnh 16: B tr cc widget trong FrameLayout................................................................... 13
Hnh 17: B tr widget trong RelativeLayout ....................................................................... 14
Hnh 18: B tr widget trong TableLayout ........................................................................... 15
Hnh 19: ImageButton .......................................................................................................... 16
Hnh 20: ImageView v ImageButton .................................................................................. 17
Hnh 21: Minh ha cho mt ListView .................................................................................. 18
Hnh 25: Truyn d liu gia 2 Acticity .............................................................................. 21
Hnh 26: Cc thuc tnh ca Intent ...................................................................................... 21
Hnh 27: Cc Action c nh ngha sn trong Intent ................................................... 22
Hnh 27: SQLite Manager .................................................................................................... 22
Hnh 28. Biu ca s dng tng qut ................................................................................ 26
Hnh 29. Biu ca s dng xem qun n ........................................................................... 27
Hnh 30. Biu ca s dng ng b facebook ................................................................... 28
Hnh 31. Biu ca s dng xem bn ............................................................................. 28
Hnh 32. Biu ca s dng hc nu n .............................................................................. 29
Hnh 33. Biu hot ng Tm kim ................................................................................. 30
Hnh 34. Biu hot ng Bn ..................................................................................... 31
Hnh 35. Biu hot ng Tm ng ............................................................................... 32
Hnh 36. Biu hot ng ng nhp facebook................................................................ 33
Hnh 37. Biu hot ng Xem thng tin qun n ............................................................ 34
Hnh 38. Biu tun t Tm kim ...................................................................................... 35
Hnh 39. Biu tun t Bn .......................................................................................... 36
Hnh 40. Biu tun t Tm ng ................................................................................... 37
Hnh 41. Biu tun t ng nhp facebook .................................................................... 38
Hnh 42. Giao din mn hnh chnh...................................................................................... 40
Hnh 43. Giao din mn hnh Tm Kim .............................................................................. 41
Hnh 44. Giao din mn hnh Yu Thch ............................................................................. 41
Hnh 45. Giao din mn hnh danh sch qun n ................................................................. 42
Hnh 46. Giao din mn hnh chi tit qun n ...................................................................... 42
Hnh 47. Giao din mn hnh tm ng i .......................................................................... 43
Hnh 48. Giao din mn hnh chia s qun n ...................................................................... 43
Hnh 49. Giao din mn hnh bnh lun qun n .................................................................. 44
Hnh 50. Giao din mn hnh ch dy hng dn nu n .................................................... 44
Hnh 51. Giao din mn hnh danh sch cc mn c hng dn nu .............................. 45
Hnh 52. Giao din mn hnh chi tit hng dn nu n ...................................................... 45
Hnh 53. Giao din mn hnh bn qun n ...................................................................... 46

DANH MC BNG BIU


Bng 1. M t cc usecase trong biu ca s dng tng qut ........................................... 27
Bng 2. M t cc usecase trong biu ca s dng xem qun n ...................................... 27
Bng 3. M t cc usecase trong biu ca s dng ng b facebook ............................. 28
Bng 4. M t cc usecase trong biu ca s dng xem bn ....................................... 29
Bng 5. M t usecase trong biu ca s dng hc nu n ............................................... 29
Bng 6. C s d liu bng tblATDT .................................................................................. 39
Bng 7. C s d liu bng tblNauAn.................................................................................. 39

M U
Bi cnh ca ti

I.

Nn cng ngh thng tin ang thc s i vo giai on pht trin bc nht t trc
n nay. Nu trc kia, s ra i ca my tnh xch tay mang li s thun tin cho
ngi s dng, th sau s ra i ca chic in thoi thng minh nh du s pht trin
vt bc ca cng ngh thng tin. Mi sn phm cng ngh u nm trong chic in
thoi thng minh. Tht d dng cho cuc sng cc bn khi c cho bn thn chic in
thoi nh th.
Th gii in thoi pht trin khng ngng, nhng chic in thoi chy h iu
hnh Android u tin ra i nh du bc tin ln ca Google trong th trng
ny. S lng s dng in thoi ny cng tng do c nhiu tnh nng v gi c kh
mm.
Ngy nay vic thng thc m thc cng ngy cng tr nn khc khe hn i vi
thc khch,nhng qun n cng tr nn phong ph v m rng nhiu ni khp thnh
ph. Vic tm c mt qun n ng hay ch l nh ra qun n v tr no cng ht
sc kh khn hn.
Vi nhng suy ngh em quyt nh chn ti Xy dng ng dng m thc
Thnh trn nn tng Android,gip gii quyt c kh khn trong vic tm kim qun
n ch vi thit b cm tay.

Mc ch v ngha ca ti

II.
II.1.

Mc ch ca ti

Lun vn tt nghip trn tng ti vi hai mc ch chnh nh sau :


Th nht l tm hiu v k thut lp trnh ng dng vi Android SDK
Th hai l xy dng ng dng trn thit b di ng Android c kh nng trin
khai ng dng vo thc t,em li s tin li cho ngi s dng c th tra
cu mi ni.
Vi nhng kin thc hc c ti trng, kt hp vi s tm hiu cng ngh ca
c nhn. Em hy vng lun vn tt nghip ca em s t c kt qu nh mong i.

II.2.

ngha ca ti

Trc ht, ng dng m thc Thnh c xy dng nh mt ti th hin


vic p dng nhng kin thc qu bu c cc Thy, C ca trng i hc Bch
Khoa i hc Nng nhit tnh truyn t li cho em. V c bit l s theo di
SVTH: Ha Bch Trung Lp 11TLT

Trang 1

Xy dng ng dng m thc Thnh trn nn tng Android

v tn tnh gip ca C L Th M Hnh trong sut thi gian em thc hin ti


ny.
Trong thi i cng ngh thng tin pht trin nh v bo ngy nay, cng ngh khng
ngng c ci tin, nhng cng ngh mi ra i i hi ngi lp trnh vin phi c
gn nghin cu v tm hiu p dng vo thc tin. iu ny cng c th hin qua
s c gng ca em khi quyt nh thc hin ti ny vi cng ngh c coi l mi
hin nay v c pht trin mnh m trong tng lai.
ng dng c th ni nh l mt ph kin i km theo cc b ni tr h tr cho
cc b lm tt hn trong vic chun b ba cm cho gia nh.

III.

Nhim v ca ti

ng dng m thc Thnh l mt ng dng chy trn nn Android. Di y


l cc chc nng chnh m em d nh thc hin trong ng dng nh sau:
Ngi dng c th tm kim cc a im qun n trn a bn thnh ph
Nng
Ngi dng c th xem tt c cc qun n,thng tin chi tit qun n.
Thm qun n vo danh sch yu thch.
Ngi dng c th xem ch dn ng i t v tr ang ng ti qun n mun
n.
C th gi in trc tip t ng dng.
ng dng c chc nng hin th cc qun n ln bn ngi dng nh
hng v chn qun n ngay trn bn .
ng dng c chc nng hng dn nu mt s mn n theo tng loi c th.
C th chia s qun n v bnh lun v qun n ang xem.

IV.

Ni dung nghin cu
Tm hiu cng ngh Android v k thut cn thit lp trnh ng dng in
thoi Android.
Phn tch cc yu cu cn thit ca ti.
Phn tch thit k h thng.
Xy dng c s d liu.
Xy dng ng dng vi y cc chc nng cn thit.
Vit bo co tng kt ti v ra hng pht trin.

SVTH: Ha Bch Trung Lp 11TLT

Trang 2

Xy dng ng dng m thc Thnh trn nn tng Android

CHNG 1

C S L THUYT
I.
I.1.

H iu hnh Android
Lch s ca Android

Nm 2003, mt cng ty hot ng trong lnh vc pht trin phn mm cho cc thit
b di ng mng tn Android c thnh lp bi 4 thnh vin l:
1. Andu Rubin: nh ng sng lp cng ty Danger cng ty chuyn v cc nn
tng, phn mm, thit k v dch v cho cc thit b in ton di ng
2. Rich Miner: nh ng sng lp cng ty truyn thng Wildfire
Communications
3. Nick Sears: mt trong nhng v ph ch tch ca nh cung cp mng vin
thng di ng T-Mobile M
4. Chris While: trng b phn thit k v pht trin giao din WebTV
Nm 2005, sau hn 2 nm hot ng th Android c Google mua li vi mt
khon tin khng c tit l v chnh thc tr thnh mt trong nhng cng ty con ca
g khng l ngnh tim kim. ng thi c Andy Rubin, Rich Miner v Chris While
u quyt nh tip tc lm vic ti chnh cng ty ca mnh sau khi c mua li.
thi im , nhiu ngi khng thc s ch vo thng v ny th nhng n li
nh du bc i u tin ca Google trong th trng thit b di ng th gii.
Ti Google, mt nhm nghin cu ng u l Rubin bt u pht trin mt nn
tng dnh cho thit b di ng da trn nhn ca h iu hnh Linux. V sau h iu
hnh ny cng c gii thiu n cc nh pht trin phn cng ln phn mm, bo
hiu s c mt ca mt ngi sao khc trn thin h th trng cng ngh di ng.
n thng 12 nm 2006, suy on v nh gia nhp th trng truyn thng di
ng ca Google tip tc c cng c sau khi BBC v The Wall Street Journal cho
bit rng hang ny mun a ng dng v chc nng tm kim ca mnh ln cc thit
b di ng. Lp tc ngay sau , nhiu tin n v chic in thoi mang thng hiu
Google xut hin khp cc phng tin truyn thng.
Thng 7 nm 2007, lin minh cc nh sn xut thit b cm tay Open Handset
Alliance (OHA) c thnh lp bao gm Google v mt s thnh vin khc ca cng
ng Linux nh: Broadcom Corporation, Google, HTC, Intel, LG, Marvell Technology
Group, Motorola, Nvidia, Qualcomm, Samsung Electronics, Sprint Nextel, T-Mobile
v Texas Instruments. Mc tiu ca OHA l pht trin tiu chun m cho cc thit b di
ng v sn phm u tin ca lin minh ny l Android, mt nn tng di ng c
xy dng trn nhn Linux phin bn 2.6.
SVTH: Ha Bch Trung Lp 11TLT

Trang 3

Xy dng ng dng m thc Thnh trn nn tng Android

Tnh cho ti thi im ny, Google Android c 5 phin bn chnh thc v 1 phin
bn sp ra mt c t tn theo nhng mn trng ming, vi ng ngi dung s d
dng s dng h iu hnh ca h nh thng thc cc mn n . Cc phin bn
Android c tn m ln lt l: Cupcake 1.5, Donut 1.6, cair 2.0, Froyo 2.2,
Gingerbread 2.3, Honeycomb 3.0/3.1,, v cc phin bn sp ra mt l Android Ice
Cream Sandwich.

I.2.

Kin trc ca Android

M hnh sau th hin mt cch tng qut cc thnh phn ca h iu hnh Android.
Mi mt phn s c c t mt cch chi tit di y.

Hnh 11: Cu trc h thng Android

I.2.1.

Tng ng dng

Android c tch hp sn mt s ng dng cn thit c bn nh: contacts, brower,


camera, phone, Tt c cc ng dng chy trn h iu hnh Android u vit bng
java.
I.2.2.

Application framework

Bng cch cung cp mt nn tng pht trin m, Android cung cp cho cc nh pht
trin kh nng xy dng cc ng dng cc k phong ph v sng to. Nh pht trin
c t do tn dng cc thit b phn cng, thng tin a im truy cp, cc dch v

SVTH: Ha Bch Trung Lp 11TLT

Trang 4

Xy dng ng dng m thc Thnh trn nn tng Android

chy nn, thit lp h thng bo ng, thm cc thng bo cc thanh trng thi, v
nhiu, nhiu hn na.
Nh pht trin c th truy cp vo cc API cng mt khun kh c s dng bi
cc ng dng li. Cc kin trc ng dng c thit k n gin ha vic s dn li
cc thnh phn, bt k ng dng no c th xut bn kh nng ca mnh v ng dng
no khc sau c th s dng nhng kh nng (c th hn ch bo mt c thc thi
bi khun kh). C ch ny cho php cc thnh phn tng t s c thay th bi
ngi s dng.
C bn tt c cc ng dng l mt b cc dch v v cc h thng bao gm:
-

Mt tp hp rt nhiu cc View c kh nng k tha ln nhau dung thit


k giao din ng dng nh: gridview, tableview, linearlayout

Mt Content Provider cho php cc ng dng c th truy xut d liu t


cc ng dng khc (chng hn nh Contacts) hoc chia s d liu gia cc
ng dng .

Mt Resource Manager cung cp truy xut ti cc ti nguyn khng phi


l m ngun chng hn nh: localized string graphics v layout files.

Mt Notifycation Manager cho php tt c cc ng dng hin th custom


alerts trong status bar.

Activity Manager c dng qun l chu trnh sng ca ng dng v iu hng


cc activity.
I.2.3.

Library

Android bao gm mt tp hp cc th vin C/C++ c s dng bi nhiu thnh


phn khc nhau trong h thng Android. iu ny c th hin thng qua nn tng
ng dng Andorid. Mt s th vin c bn c lit k di y:
System C library: c ngun gc t h thng th vin chun C (LIBC) gip
iu chnh nhng cho cc thit b s dng nn tng Linux.
Media Libraries: da trn OpenCore ca PacketVideo, h tr ghi v pht
li m thanh, hnh nh, video di nhiu nh dng ph bin nh MPEG4,
H.264, MP3, AAC, AMR, JPG v PNG
LibWebCore: trnh duyt web hin i h tr c trnh duyt web ca
Android v cc trnh duyt web nhng khc.
3D Libraries: da trn OpenGL ES 1.0 API, dng tng tc phn cng 3D
(nu c) hoc ti u ha cc phn mm 3D.
SQLite: c s d liu dng cho tt c cc ng dng

SVTH: Ha Bch Trung Lp 11TLT

Trang 5

Xy dng ng dng m thc Thnh trn nn tng Android

I.2.4.

Android Runtime

Cung cp cc chc nng c sn trong th vin gc ca ngn ng lp trnh Java. Mi


ng dng trn h iu hnh Android s chy trn mt tin trnh ca ring n. V d: cc
my o Dalvik chy trn cc lp c bin son bi mt trnh bin dch ngn ng Java
v c chuyn i sang nh dng Dalvik (.dex) bng cng c dx tch hp. Cc tp
tin c thc thi di dng .dex s gip ti u ha cng nh qun l b nh cp
thp.
I.2.5.

Linux Kernel

Android hot ng da trn nhn h iu hnh Linux 2.6 qua cung cp cc dch
v cho h thng ct li nh an ninh, qun l b nh, qu trnh hay m hnh iu khin
ng thi nhn h iu hnh hot ng nh mt lp tru tng gip kt ni gia phn
cng v phn mm cn li trn nn tng.

I.3.

Android Emulator

Android SDK v Plugin Eclip c gi l mt Android Deverloper Tool (ADT).


Cc Android coder s cn phi s dng cng c IDE (Integrated Development
Enveronment) ny pht trin, debugging v testing cho ng dng. Tuy nhin, cc
coder cng c th khng cn phi s dng IDE m thay vo l s dng command
line bin dch v tt nhin l vn c Emulator nh thng.
Android Emulator c trang b y hu ht cc tnh nng ca mt thit b tht.
Tuy nhin, mt s b gii hn nh l kt ni qua cng USB, camera v video, nghe
phone, ngun in gi lp v Bluetooth.
Android Emulator thc hin cc cng vic thng qua mt b x l m ngun m,
cng ngh ny c gi l QEMU c pht trin bi Fabrice Bellard.

SVTH: Ha Bch Trung Lp 11TLT

Trang 6

Xy dng ng dng m thc Thnh trn nn tng Android

Hnh 12: Android emulator

I.4.

Cc thnh phn ca mt ng dng Android

- Activity

Mt ng dng c giao din ngi dng nhn thy c, s c thc hin bng
mt Activity. Activity dng Views o nn giao din ha ngi dng, hin th
thng tin v p li hnh ng ca ngi dng. Khi ngi dng chn mt ng dng t
mn hnh ch hoc trnh khi chy ng dng th mt Activity c khi ng. Activity
trong Android cng tng t nh mt Form trong cc ng dng destop truyn thng.
Vng i ca ng dng Android
Activity l thnh phn quan trng nht v ng vai tr chinh trong xy dng
ng dng Android
H iu hnh Android qun l Activity theo dng stack: khi mt Activity mi
c khi to, n s c xp ln u ca stack v tr thnh running activity, cc
Activity trc s b tm dng v ch hot ng tr li khi Activity mi c gii
phng.
Cc trng thi trong Activity:
- Running: Activity ang hin th trn mn hnh
- Paused: Activity vn hin th nhng khng th tng tc
- Activity b thay th hon ton bi Activity mi s tin n trng thi stop

SVTH: Ha Bch Trung Lp 11TLT

Trang 7

Xy dng ng dng m thc Thnh trn nn tng Android

- Killed: khi h thng b thiu b nh, n s gii phng cc tin trnh theo

nguyn tc u tin. Cc Activity trng thi stop hoc paused cng c th


b gii phng v khi n c hin th li th cc Activity ny c khi
ng li hon ton v phc hi li trng thi trc .

Hnh 13: Vng i ca Activity


- Service

Service l mt ng dng component c th thc hin cc hot ng long-running


trong background v khng cung cp mt giao din ngi dng. Mt ng dng
component c th bt u mt service v n tip tc chy trong background thm ch
nu ngi dng chuyn cho ng dng khc. Ngoi ra, mt component c th lin kt
cho mt dch v tng tc vi n v thm ch thc hin giao tip InterProcess. V d,
mt dch v c th x l giao din mng, nghe nhc, thc hin cc tp tin I/O hoc
tng tc vi mt provider content, tt c t background.
Mt service c bn c th c hai hnh thc nh sau:
Started
Service l started khi mt component ng dng bt u n bng cch gi
startService(). Khi bt u, mt service c th chy trn background v thi hn, ngay
c khi cc thnh phn bt u n b ph hy. Thng thng, mt service bt u
thc hin mt hot ng n l v khng tr li kt qu cho ngi gi. V d, n c th
ti v hoc ti ln mt tp tin qua mng.Khi hot ng c thc hin, cc service nn
dng li bn thn

SVTH: Ha Bch Trung Lp 11TLT

Trang 8

Xy dng ng dng m thc Thnh trn nn tng Android

Bound
Service l bound khi mt component ng dng lin kt cho n bng cch gi
bindService(). Mt service rang buc cung cp mt giao din client-server cho php cc
component tng tc vi cc dch v, gi cc yu cu, c c kt qu v thm ch lm
nh vy qua qu trnh giao tip InterProcess. Mt service bound ch chy min l ng
dng component khc b rang buc vo n. Nhiu thnh phn c th lin kt cho dch
v cng mt lc, nhng khi tt c chng unbind, service ny b ph hy.
to ra mt service, bn phi to mt lp dch v. Trong implementation ca
bn, bn cn cho ghi ln mt s method gi li c th x l cc kha cnh quan trng
ca vng i service v cung cp mt c ch cho cc component gn kt vi dch v
nu thch hp. Cc method quan trng nht bn c nn ghi ln gi l:
- onStartCommand()

H thng gi method ny khi component nh l mt Activity, yu cu cc


service c started, bng cch gi startService(). Sau thc hin phng php ny,
cc service c khi ng v c th chy trong background v thi hn. Nu bn c
trin khai iu ny, l trch nhim ca bn dng dch v khi cng vic ca mnh
c thc hin, bi stopSelf gi in thoi () hoc stopService().
- onBind()

H thng ny gi method ny khi component mun lin kt vi cc


service, bng cch gi bindService(). Trong implemention ca phng thc ny, bn
phi cung cp mt giao din khch hng s dng giao tip vi dch v, bng cch
tr li mt IBinher. Bn lun lun phi trin khai phng php ny, nhng bn khng
mun cho php lin kt, sau bn nn tr v null.
- onCreate()

H thng gi method ny khi service u tin to ra, thc hin cc th


tc thit lp mt ln (trc khi cuc gi hoc l onStartCommand() hoc onBind()).
Nu service ang chy, phng pho ny khng c gi.
- onDestroy()

H thng gi method ny khi service khng cn c s dng v ang


c b ph hy. Service ca bn nn trin khai iu ny cho lm sch bt c ngun ti
nguyn nh ch , ngi nghe a ng k, nhn ..v..v. y l cc cuc gi qua dch
v ny nhn c.
- Content Provider

C th coi nh l mt my ch c s d liu. Cng vic ca n l qun l truy cp


v chia s d liu ang tn ti, chng hn nh mt c s d liu SQLite. N c th c
cu hnh cho php cc ng dng khc truy xut v ngc li. Nu ng dng rt n
gin th khng nht thit phi to ra mt trnh cung cp ni dung.
SVTH: Ha Bch Trung Lp 11TLT

Trang 9

Xy dng ng dng m thc Thnh trn nn tng Android

Content Provider gip tch bit tng ng dng ra khi tng d liu. N c y
cc quyn iu khin v c truy xut thng qua m hnh URI n gin nh l c th
thm, xa, cp nhp d liu ca cc ng dng.
- Broadcats Receiver

Bng cch to v ng k mt Broadcast Receiver, ng dng Android c th lng


nghe ton b cc Intent theo mt chun c th c ch nh. Cc Broadcast Receiver
s chy ng dng mt cch t ng p ng mt Intent gi n, hay x l mt phn
t d liu hoc p ng mt s kin, chng hn nh nhn mt vn bn thng bo.
Broadcast Receiver ch c duy nht mt phng thc onReceiver():
Khi c s kin m Broadcast Receiver ng k nhn c pht i, th
phng thc onReceiver() ca Broadcats Receiver s c gi.
Sauk hi thc thi xong phng thc ny, vng i ca mt Broadcast Receiver
kt thc.

I.5.

Cu trc mt Project

Mt Android project bao gm cc th mc sau:


Th mc src cha source code ng dng. Gm cc package v cc class
Th mc gen cha cc file t ng pht sinh (m thng gp nht l R.class)
Th mc res cha cc resource dng trong ng dng (thng qua ID)
Th mc assets cha cc resource file m ng dng cn dng (di dng file)
File Manifest l file khai bo thng tin v ng dng vi h thng (nh ng
dng gm nhng activity no, c service no xin cc quyn g, phin bn
bao nhiu, dng t SDK phin bn no..).
File th vin

II.

Cng c to mt ng dng Android

Cch d nht bt u pht trin cc ng dng Android l ti v B cng c pht


trin phn mm Android v Mi trng pht trin tch hp Eclipse (Eclipse IDE) Vic
pht trin Android c th din ra trn Microsoft Windows, Mac OS X, hoc Linux.
Trong bi lun vn ny, nhm chng em chn pht trin ng dng Android bng
Microsoft Windows.

II.1.

Eclipse IDE

Cc ng dng Android c vit bng ngn ng Java nhng bin dch v thi hnh
bng my o Dalvik. Vit m bng ngn ng Java trong Eclipse l rt trc quan. Eclipse
cung cp mi trng Java phong ph, gm c vic tr gip theo ng cnh v cc mch
SVTH: Ha Bch Trung Lp 11TLT

Trang 10

Xy dng ng dng m thc Thnh trn nn tng Android

nc gi v m. Khi b m Java c bin dch thnh cng, Android Deverloper


Tools s m bo rng ng dng c ng gi mt cch ng n, gm c tp tin
Android Manifest.xml.

II.2.

Android SDK

B cng c pht trin ng dng Android SDK l cng c gi lp thit b o trn my


tnh pht trin ng dng vi cc hm API h tr cho lp trnh vin lp trnh trn cc
thit b di ng s dng nn tng Android thng qua ngn ng lp trnh Java. SDK gm
c:
Android.jar: tp tin lu tr Java cha ton b cc lp SDK Android cn thit
xy dng ng dng.
Document.html v th mc docs: ti liu SDK c cung cp ti ch v trn
web, ch yu n dng JavaDocs, to iu kin d dng cho vic hng dn
trong nhiu gi SDK. Ti liu cng gm c hng dn pht trin mc cao v
cc lin kt n cng ng Android rng ri.
Th mc sample (cc v d mu): th mc con samples cha b m ngun
y dng cho mt lot cc ng dng, gm c ApiDemo, n s dng nhiu
API. ng dng mu l mt ni khm ph tuyt vi khi bt u pht trin ng
dng Android.
Th mc tools (cc cng c): cha ton b cc cng c dng lnh xy
dng nn cc ng dng Android. Cng c c dng ph bin v hu ch
nht l tin ch adb (Android Debug Bridge).
Usb__driver: th mc cha cc trnh iu khin cn thit kt ni mi
trng pht trin vi mt thit b c kh nng chy Android, chng hn nh
G1 hay in thoi c pht trin Android Dev 1. Cc tp tin ny l i
hi duy nht i vi cc nh pht trin ang s dng nn Windows.

III.
III.1.

Cc thnh phn giao din trong Android


View

Trong mt ng dng Android, giao din ngi dng c xy dng t cc i tng


View v ViewGroup. C nhiu kiu View v ViewGroup. Mi mt kiu l mt hu du
ca classs View v tt c cc kiu c gi l cc Widget.
Tt c mi widget u c chung cc thuc tnh c bn nh l cch trnh by v tr,
background, kch thc, l Tt c nhng thuc tnh chung ny c th hin ht
trong i tng View
Trong Android Platform, cc screen lun c b tr theo mt kiu cu trc phn
cp nh hnh di. Mt screen l mt tp hp cc Layout v cc widget c b tr c
SVTH: Ha Bch Trung Lp 11TLT

Trang 11

Xy dng ng dng m thc Thnh trn nn tng Android

th t. th hin mt screen th trong hm onCreate ca mi Activity cn phi c


gi mt hm l setContentView(R.layout.main), hm ny s load giao din t file xml
ln phn tch thnh m bytecode.

Hnh 14: Cu trc mt giao din ng dng Android

III.2.

ViewGroup

ViewGroup thc ra chnh l View hay ni ung shown th ViewGroup chnh l cc


widget Layout c dng b tr cc i tng khc trn mt screen. C mt s loi
ViewGroup nh sau:
III.2.1. LinearLayout
LinearLayout c dng b tr cc thnh phn giao din theo chiu ngang hoc
chiu dc nhng trn mt line duy nht m khng c xung dng.
LinearLayout lm cho cc thnh phn trong n khng b ph thuc vo kch thc
ca mn hnh. Cc thnh phn trong LinearLayout c dn theo nhng t l cn xng
da vo cc rng buc gia cc thnh phn.

SVTH: Ha Bch Trung Lp 11TLT

Trang 12

Xy dng ng dng m thc Thnh trn nn tng Android

Hnh 15: B tr cc widget s dng LinearLayout

III.2.2. FrameLayout
FrameLayout c dng b tr cc i tng theo kiu ging nh cc Layer trong
Photoshop. Nhng i tng no thuc Layer bn di th s b che khut bi cc i
tng thuc Layer nm trn. FrameLayout thng c s dng khi mun to ra cc
i tng c khung hnh bn ngoi chng hn nh contact image button.

Hnh 16: B tr cc widget trong FrameLayout

III.2.3. AbsoluteLayout
Layout ny c s dng b tr cc widget vo mt v tr bt k trong layout da
vo 2 thuc tnh ta x,y. Tuy nhin, kiu layout ny rt t khi c dng bi v ta
ca cc i tng lun c nh v s khng c iu chnh c t l khong cch
SVTH: Ha Bch Trung Lp 11TLT

Trang 13

Xy dng ng dng m thc Thnh trn nn tng Android

gia cc i tng. Khi chuyn ng dng sang mt mn hnh c kch thc vi mn


hnh thit k ban u th v tr ca cc i tng s khng cn chnh xc nh ban u.
III.2.4. RetaliveLayout
Layout ny cho php b tr cc widget theo m trc i xng ngang hoc dc.
t c ng v tr th cc widget cn c xc nh mt mi rng buc no vi cc
widget khc. Cc rng buc ny l cc rng buc tri, phi, trn, di so vi mt widget
hoc so vi layout parent. Da vo nhng mi rng buc m RetaliveLayout cng
khng ph thuc vo kch thc ca screen thit b. Ngoi ra, n cn c u im l gip
tit kim layout s dng nhm mc ch gim lng ti nguyn s dng khi load ng
thi y nhanh qu trnh x l.

Hnh 17: B tr widget trong RelativeLayout

III.2.5. TableLayout
Layout ny c s dng khi cn thit k mt table cha d liu hoc cn b tr cc
widget theo cc row v column. Chng hn nh, giao din ca mt chic my tnh n
gin hoc danh sch d liu.

SVTH: Ha Bch Trung Lp 11TLT

Trang 14

Xy dng ng dng m thc Thnh trn nn tng Android

Hnh 18: B tr widget trong TableLayout

III.3.

Button

S d widget button c gii thiu u tin trong s cc widget khc l v y l


i tng c th ni l c dng nhiu nht trong hu ht cc ng dng Android.
thit k giao din vi mt button ta c 2 cch nh sau:
Thit k bng XML
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cmdButton1"
android:text="Touch me!"
android:onClick="touchMe"/>

Thuc tnh android:onClick =touchMe c dng nm bt s kin click


vo button. Khi s kin click button xy ra th phng thc touchMe c khai bo
trong th thuc tnh s c gi. Nu trng hp phng thc touchMe cha c
khai bo trong file m ngun tng ng th s pht sinh mt exception. Ngc li,
phng thc touchMe s nhn c mt i tham bin l i tng View ni sinh
ra s kin. i vi View ny c th p kiu trc tip sang kiu Button v thc cht n
l mt button.
V d: trong file m ngun khai bo mt hm nh sau:

SVTH: Ha Bch Trung Lp 11TLT

Trang 15

Xy dng ng dng m thc Thnh trn nn tng Android

public void touchMe(View v){


Button me = (Button) v;
Me.setText(Touched);
}

Thit k bng code


Thc ra m ni th nu khng phi i hi phi custom li mt widget th khng
cn phi s dng ti code. Trong mt s trng hp bt buc chng ta phi custom cc
widget cho ph hp vi hon cnh. Chng hn nh trong game, cc menu hay cc
nt iu khin,.
khai bo mt Button trong code ta lm nh sau:
Button cmdButton = new Button(this);
cmdButton.setText(Touch Me!);
cmdButon.setOnClickListener();

custom mt widget no ta phi to mt class k tha t mt class widget


mun custom, sau s dng hm draw v li widget nh mt Canvas.
VD: canvas.drawPicture(Picture.createFromStream(...));

III.4.

ImageButton

Cng tng t nh Button, ImageButton ch c thm mt thuc tnh android:src =


@drawable/icon thm hnh nh vo v khng c th text
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cmdButton1"
android:src="@drawable/icon"
android:onClick="touchMe"/>

Hnh 19: ImageButton

III.5.

ImageView

c dng th hin mt hnh nh. N cng ging nh ImageButton, ch khc l


khng c hnh dng ca mt ci button.
SVTH: Ha Bch Trung Lp 11TLT

Trang 16

Xy dng ng dng m thc Thnh trn nn tng Android

Code:
ImageView iv = new ImageView(this);
iv.setImageResource(R.drawble.icon)

Hnh 20: ImageView v ImageButton

III.6.

ListView

c s dng th hin mt danh sch cc thng tin theo tng cell. Mi cell thng
thng c load ln t mt file XML c c nh trn s lng thng tin v
loi thng tin cn c th hin.
thc hin c mt list thng tin ln mt screen th cn phi c 3 yu t chnh:
Data Source: Data Source c th l mt ArrayList, HashMap hoc bt k
mt cu trc d liu kiu danh sch no.
Adapter: Adapter l mt class trung gian gip nh x d liu trong Data
Source vo ng v tr hin th trong ListView. Chng hn, trong Data Source
c mt trng name v trong ListView cng c mt TextView th hin
trng name ny. Tuy nhin, ListView s khng th hin th d liu trong
Data Source ln c nu nh Adapter khng gn d liu vo cho i tng
hin th.
ListView: ListView l i tng hin th cc thng tin trong Data Source
ra mt cch trc quan v ngi dng c th thao tc trc tip trn .

SVTH: Ha Bch Trung Lp 11TLT

Trang 17

Xy dng ng dng m thc Thnh trn nn tng Android

Hnh 21: Minh ha cho mt ListView

III.7.

TextView

TextView ngoi tc dng l hin th vn bn th n cn cho php nh dng ni


dung bng th html.
V d:
TextView textView = (TextView)findViewById(R.id.textView);
CharSequence styledText =
Html.fromHtml("<i>This</i> is some <b>styled</b> <s>text</s>");
textView.setText(styledText);

Ni dung TextView cng c th c nh dng bng th html ngay trong XML

III.8.

EditText

Trong Android i tng EditText c s dng nh mt TextField hoc mt


TextBox.
<EditText
android:id="@+id/EditText01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="20dip"
android:textColor="#000000"

SVTH: Ha Bch Trung Lp 11TLT

Trang 18

Xy dng ng dng m thc Thnh trn nn tng Android

android:text="Hello Android!"
android:singleLine="true"
android:inputType="textCapWords"/>

Cc thuc tnh cn ch s dng EditText l:


Android:inputType = s dng xc nh phng thc nhp cho
EditText. Chng hn nh khi bn mun mt nhp password hay mt
nhp Email th thuc tnh ny s lm iu .
Android:singleLine = true EditText ca bn s tr thnh mt TextField,
ngc li s l TextBox.

III.9.

CheckBox

Nhn 2 gi tr true hoc false. i tng CheckBox cho php chn c nhiu item
cng mt lc.
Khai bo: CheckBox cb = new CheckBox (Context);
XML:
<CheckBox
android:id="@+id/CheckBox01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Check me"
android:checked="true"/>

III.10. Acvivity & Intend


III.10.1. Activity
Activity l mt thnh chnh ca ng dng Android, c dng hin th mt mn
hnh v nm bt cc hot ng xy ra trn mn hnh . Khi lm vic vi Activity cn
nm bt c mt s kin thc c bn nh sau:
Chu k sng ca mt Activity
To menu v dialog
Khi ng mt Activity
khi ng mt Activity ta thng s dng Intent. Tuy nhin, trong phn ny s
hng dn cch chuyn gia cc Intent theo 2 loi:
-

Intent tng mnh Explicit Intent: xc nh r mt thnh phn (Activity,


BroadcastReceiver, Service) thng qua phng thc setComponent

SVTH: Ha Bch Trung Lp 11TLT

Trang 19

Xy dng ng dng m thc Thnh trn nn tng Android

(ComponentName) hoc setClass (Context, Class) s thc thi cc hnh ng


c c t trong Intent. Thng thng th nhng Intent ny khng cha bt
k thng tin no khc nh category , type m n gin ch l cch ng
dng m cc Activity khc bn trong mt Activity.
-

Intent khng tng minh Implicit Intent: khng ch nh mt thnh phn


no c, thay vo , chng s cha thng tin h thng c th xc nh
component c sn no l tt nht thc thi hiu qu cho Intent .

Tnh lin lc gia 2 activity: Khi chuyn sang mt Activity khc ta c th gi km


d liu trong intent nh sau:
intent.putExtra (key1,value1);
intet.putExtra (key2,23);

Bn pha Activity c khi ng hay c chuyn n n, c th ly d liu c


gi nh sau:
getIntent().getExtra().getString(key1);
getIntent().getExtra.getInt(key2);

Task: Android l mt h iu hnh a tin trnh. Khi lp trnh trn nn tng Android
th tin trnh l mt vn cn phi c ch nhiu nht. Mc d Android h tr a
tin trnh nhng trn mt thit b di ng vi cu hnh thp m chng ta qu lm dng
tin trnh th s rt tn b x l iu ny cng ng ngha vi vic bn ang bin ng
dng ca bn tr thnh mt th phn mm tiu th in nng.
III.10.2. Intent
Khi nim Intent
L mt cu trc d liu m t cch thc, i tng thc hin ca mt Activity
L cu ni gia cc Activity: ng dng Android thng bao gm nhiu
Activity, mi Activity hot ng c lp vi nhau v thc hin nhng cng vic khc
nhau. Intent chnh l ngi a th, gip cc Activity c th triu gi cng nh truyn
cc d liu cn thit ti mt Activity khc. iu ny cng ging nh vic di chuyn qua
li gia cc Forms trong lp trnh Windows Form.

SVTH: Ha Bch Trung Lp 11TLT

Trang 20

Xy dng ng dng m thc Thnh trn nn tng Android

Hnh 25: Truyn d liu gia 2 Acticity

D liu ca Intent
Intent v c bn l mt cu trc d liu, c m t trong lp
android.content.Intent.
Cc thuc tnh ca i tng Intent:

Hnh 26: Cc thuc tnh ca Intent


Cc Action c nh ngha sn:
Di y l nhng hng String c nh ngha sn trong lp Intent. i km vi
n l cc Activity hay Application c xy dng sn s c triu gi mi khi Intent
tng ng c gi (tt nhin khi c cung cp ng data). VD: Gi ti mt s in
thoi.
Intent dialIntent = new Intent (Intent.ACTION_DIAL, Uri.parse(tel: 123456));
startActivity (dialIntent);

SVTH: Ha Bch Trung Lp 11TLT

Trang 21

Xy dng ng dng m thc Thnh trn nn tng Android

Hnh 27: Cc Action c nh ngha sn trong Intent

IV.

SQLite

SQlite l mt dng CSDL tng t nh Mysql, PostgreSQL... c im ca SQLite


l gn, nh, n gin. Chng trnh gm 1 file duy nht vn vn cha n 500kB, khng
cn ci t, khng cn cu hnh hay khi ng m c th s dng ngay. D liu database
cng c lu mt file duy nht. Khng c khi nim user, password hay quyn hn
trong SQLite database.
SQLite khng thch hp vi nhng h thng ln nhng quy m va tm th SQLite
pht huy uy lc v khng h yu km v mt chc nng hay tc . Vi cc c im
trn SQLite c s dng nhiu trong vic pht trin, th nghim v..v.. v l s la
chn ph hp cho nhng ngi bt u hc database. Hin nay th SQLite c ng
dng vo smartphone nh iPhone v Android lu tr d liu.
c th d dng thao tc vi SQLite chng ta c th s dng trnh duyt FireFox
v ti v plugin SQLite ti link sau: http://code.google.com/p/sqlite-manager/.
Sau khi ci t plugin xong th vo Menu_tools trong firefox s c chc nng SQLite
Manager. Giao din ca SQLite manager trong firefox nh sau:

Hnh 27: SQLite Manager


SVTH: Ha Bch Trung Lp 11TLT

Trang 22

Xy dng ng dng m thc Thnh trn nn tng Android

V.

GPS
H thng nh v ton cu (ting Anh: Global Positioning System - GPS) l h

thng xc nh v tr da trn v tr ca cc v tinh nhn to. Trong cng mt thi im,


mt v tr trn mt t nu xc nh c khong cch n ba v tinh (ti thiu) th s
tnh c to ca v tr . GPS c thit k v qun l bi B Quc phng Hoa
K, nhng chnh ph Hoa K cho php mi ngi s dng n min ph, bt k quc
tch.
Vi h thng nh v GPS ta c th d dng xc nh v tr ca mt thit b c h
tr GPS.

VI. Google Map


Google map l mt dich v ng dng v cng ngh bn trc tuyn trn web
min ph c cung cp bi Google v h tr nhiu dch v da vo bn nh Google
Ride Finder v mt s c th nhng vo cc trang web ca bn th ba thng qua Google
Map API. N cho php thy bn ng s, v nhng a im kinh doanh trong khu
vc trn khp th gii.
Mt sn phm lin qua, l Google Earth, mt ng dng c lp dnh cho
Microsoft Windows, Mac OS X v Linux cho php xem cc tnh nng m rng khc.

SVTH: Ha Bch Trung Lp 11TLT

Trang 23

Xy dng ng dng m thc Thnh trn nn tng Android

CHNG 2

PHN TCH THIT K H THNG


I.

Phn tch yu cu
c t bi ton

I.1.

Nng hin nay th vic th ha din ra nhanh chng,cc con ng nhiu


hn,hng qun cng theo m phong ph v s lng v cc loi m thc khc nhau.
V th nh c v tr tng qun n ngon tr nn ht sc kh khn i vi mi thc
khch,bn cnh nhiu hng qun mc ln m chng ta li khng th bit do v tr
xa v kh tm.
ng dng m thc thnh c pht trin gip cho ngi dng Android
Nng c th tm kim cc qun n tng ti hoc cha ti,bn cnh l nhn xt v
nh gi v cht lng cng nh gi c ca mi qun. Ngi dng c th tm kim
nhiu loi m thc khc nhau trn thnh ph nh: cc mn si,mn nhu,mn
chay,kem-ch,ng dng c th v ng i t v tr hin ti ca ngi dng n qun
n cn tm trn bn v cho bit khong cch t ngi dng ti qun n.

I.2.

Cc chc nng chnh ca h thng

I.2.1.

ng b facebook
-

ng nhp bng ti khon facebook ca ngi dng.

Hin th thng tin ca ngi dng(hnh i din ,tn ngi dng facebook)
dng cho chc nng tng tc gia ngi dng ng dng.

Chia s ng dng ln trang c nhn.


Tm kim qun n

I.2.2.
-

Tm kim theo tn qun n

Tm kim theo a ch
Xem thng tin qun n

I.2.3.
-

La chn loi mn n cn tm

Chn qun n theo tng phn loi c th

Xem thng tin chi tit,nh gi v cc qun n

Chc nng yu thch


Qun n a thch

I.2.4.
-

Hin th cc qun n c yu thch

SVTH: Ha Bch Trung Lp 11TLT

Trang 24

Xy dng ng dng m thc Thnh trn nn tng Android

Ch ng qun n

I.2.5.
-

V ng i t v tr ngi dng ti qun n trn bn


Bn qun n

I.2.6.
-

Hin th tt c cc qun n ln mapview xung quanh v tr ngi dng

Hin th cc qun n theo la chn c th ln bn

Xem thng tin qun n ca tng im


Hc nu n

I.2.7.
-

Chn loi mn n

Xem hng dn nu n

SVTH: Ha Bch Trung Lp 11TLT

Trang 25

Xy dng ng dng m thc Thnh trn nn tng Android

II. Cc biu h thng


II.1. Biu ca s dng
II.1.1. Biu ca s dng tng qut

Hnh 28. Biu ca s dng tng qut

SVTH: Ha Bch Trung Lp 11TLT

Trang 26

Xy dng ng dng m thc Thnh trn nn tng Android

<<Usecase>>

Mc tiu

Tm kim
Xem mn n yu thch

Chc nng tm kim cc qun n


Chc nng xem cc mn n c yu
thch trc
Chc nng chn cc loi mn n cn xem
Nhm chc nng gip ngi dng ng b
ng dng vi ti khon facebook ca mnh
Chc nng gip ngi dng hc nu n
Chc nng xem thng tin chi tit ca qun n
Nhm cc chc nng gip ngi dng xem
v tm kim qun n trn bn

Chn loi mn n
ng b facebook
Hc nu n
Xem chi tit qun n
Xem bn

Tc nhn chnh
Ngi dng
Ngi dng
Ngi dng
Ngi dng
Ngi dng
Ngi dng
Ngi dng

Bng 1. M t cc usecase trong biu ca s dng tng qut

II.1.2. Xem qun n

Hnh 29. Biu ca s dng xem qun n

Mc tiu

<<Usecase>>
Xem chi tit qun n
Tm kim
Chn loi mn n
Mn n yu thch

Chc nng gip ngi dng xem thng tin


chi tit v qun n
Chc nng gip ngi dng tm qun n
Ngi dng chn cc phn loi mn n
xem danh sch cc mn n
Chc nng lit k cc qun n ngi dng
yu thch trc

Tc nhn chnh
Ngi dng
Ngi dng
Ngi dng
Ngi dng

Bng 2. M t cc usecase trong biu ca s dng xem qun n

SVTH: Ha Bch Trung Lp 11TLT

Trang 27

Xy dng ng dng m thc Thnh trn nn tng Android

II.1.3. ng b facebook

Hnh 30. Biu ca s dng ng b facebook

Mc tiu

<<Usecase>>
ng nhp facebook
Chia s ng dng
Bnh lun ng dng

Chc nng gip ngi dng ng b ng


dng vi ti khon facebook ca mnh
Chc nng gip ngi dng chia s ng
dng hoc cc qun n mnh thch
Chc nng cho php ngi dng vit thng
tin m t ng dng ln trang facebook ca
mnh

Tc nhn chnh
Ngi dng
Ngi dng
Ngi dng

Bng 3. M t cc usecase trong biu ca s dng ng b facebook

II.1.4. Xem bn

Hnh 31. Biu ca s dng xem bn

SVTH: Ha Bch Trung Lp 11TLT

Trang 28

Xy dng ng dng m thc Thnh trn nn tng Android

Mc tiu

<<Usecase>>
Xem ch ng
Xem bn qun n
Chi tit qun n

Chc nng gip ngi dng tham kho


ng i ti qun n cn tm
Chc nng lit k cc qun n ln bn
Chc nng xem chi tit qun n

Tc nhn chnh
Ngi dng
Ngi dng
Ngi dng

Bng 4. M t cc usecase trong biu ca s dng xem bn

II.1.5. Hc nu n

Hnh 32. Biu ca s dng hc nu n

Mc tiu

<<Usecase>>
Hng dn lm
Chn loi mn n

Chc nng gip ngi dng bit cc cng


on,nguyn liu ch bin mn n
Ngi dng chn loi mn n mun tham
kho cch ch bin

Tc nhn chnh
Ngi dng
Ngi dng

Bng 5. M t usecase trong biu ca s dng hc nu n

SVTH: Ha Bch Trung Lp 11TLT

Trang 29

Xy dng ng dng m thc Thnh trn nn tng Android

II.2. Biu hot ng


II.2.1. Tm kim

Hnh 33. Biu hot ng Tm kim

SVTH: Ha Bch Trung Lp 11TLT

Trang 30

Xy dng ng dng m thc Thnh trn nn tng Android

II.2.2. Bn

Hnh 34. Biu hot ng Bn

SVTH: Ha Bch Trung Lp 11TLT

Trang 31

Xy dng ng dng m thc Thnh trn nn tng Android

II.2.3. Tm ng

Hnh 35. Biu hot ng Tm ng

SVTH: Ha Bch Trung Lp 11TLT

Trang 32

Xy dng ng dng m thc Thnh trn nn tng Android

II.2.4. ng nhp facebook

Hnh 36. Biu hot ng ng nhp facebook

SVTH: Ha Bch Trung Lp 11TLT

Trang 33

Xy dng ng dng m thc Thnh trn nn tng Android

II.2.5. Xem thng tin qun n

Hnh 37. Biu hot ng Xem thng tin qun n

SVTH: Ha Bch Trung Lp 11TLT

Trang 34

Xy dng ng dng m thc Thnh trn nn tng Android

II.3. Biu tun t


II.3.1. Tm kim

Hnh 38. Biu tun t Tm kim

SVTH: Ha Bch Trung Lp 11TLT

Trang 35

Xy dng ng dng m thc Thnh trn nn tng Android

II.3.2. Bn

Hnh 39. Biu tun t Bn

SVTH: Ha Bch Trung Lp 11TLT

Trang 36

Xy dng ng dng m thc Thnh trn nn tng Android

II.3.3. Tm ng

Hnh 40. Biu tun t Tm ng

SVTH: Ha Bch Trung Lp 11TLT

Trang 37

Xy dng ng dng m thc Thnh trn nn tng Android

II.3.4. ng nhp facebook

Hnh 41. Biu tun t ng nhp facebook

SVTH: Ha Bch Trung Lp 11TLT

Trang 38

Xy dng ng dng m thc Thnh trn nn tng Android

III. C s d liu sqlite


III.1. Bng tblATDT
Dng lu tr thng tin cc qun n
Thuc tnh ca cc field:
Field Name

Type

ID

INTEGER, Primary key

Name

VARCHAR(50)

Address

VARCHAR(50)

Infor

VARCHAR(MAX)

Kind

INTEGER

Favorite

INTEGER

Lat

REAL

Long

REAL

Image

VARCHAR(100)

Phone

INTEGER
Bng 6. C s d liu bng tblATDT

III.2. Bng tblNauAn


Dng lu tr thng tin cc mn n
Thuc tnh cc field:
Field Name

Type

ID

INTEGER,Primary key

Name

VARCHAR(50)

Intro

VARCHAR(100)

Material

VARCHAR(MAX)

Cook

VARCHAR(MAX)

Kind

INTEGER

Image

VARCHAR(100)
Bng 7. C s d liu bng tblNauAn

SVTH: Ha Bch Trung Lp 11TLT

Trang 39

Xy dng ng dng m thc Thnh trn nn tng Android

CHNG 3

TRIN KHAI V NH GI KT QU
Hng dn ci t

I.

II.

i vi emulator trn PC th import th mc ng dng v chy d n.

i vi my tht yu cu h iu hnh android 2.2 tr ln,bt ch cho php ci


t t ngun khng xc nh v gi file apk trong th mc bin ca ng dng vo
mail cho in thoi. Hoc bt ch g ri usb dnh cho nh pht trin trong phn
ci t ca in thoi android,kt ni vi my tnh v chy chng trnh trong
eclipse qua in thoi.

Minh ha chy chng trnh

Hnh 42. Giao din mn hnh chnh

SVTH: Ha Bch Trung Lp 11TLT

Trang 40

Xy dng ng dng m thc Thnh trn nn tng Android

Hnh 43. Giao din mn hnh Tm Kim

Hnh 44. Giao din mn hnh Yu Thch

SVTH: Ha Bch Trung Lp 11TLT

Trang 41

Xy dng ng dng m thc Thnh trn nn tng Android

Hnh 45. Giao din mn hnh danh sch qun n

Hnh 46. Giao din mn hnh chi tit qun n


SVTH: Ha Bch Trung Lp 11TLT

Trang 42

Xy dng ng dng m thc Thnh trn nn tng Android

Hnh 47. Giao din mn hnh tm ng i

Hnh 48. Giao din mn hnh chia s qun n

SVTH: Ha Bch Trung Lp 11TLT

Trang 43

Xy dng ng dng m thc Thnh trn nn tng Android

Hnh 49. Giao din mn hnh bnh lun qun n

Hnh 50. Giao din mn hnh ch dy hng dn nu n


SVTH: Ha Bch Trung Lp 11TLT

Trang 44

Xy dng ng dng m thc Thnh trn nn tng Android

Hnh 51. Giao din mn hnh danh sch cc mn c hng dn nu

Hnh 52. Giao din mn hnh chi tit hng dn nu n


SVTH: Ha Bch Trung Lp 11TLT

Trang 45

Xy dng ng dng m thc Thnh trn nn tng Android

Hnh 53. Giao din mn hnh bn qun n

SVTH: Ha Bch Trung Lp 11TLT

Trang 46

Xy dng ng dng m thc Thnh trn nn tng Android

CHNG 4

KT LUN
Kt qu t c

I.
-

Hon thnh y cc yu cu t ra

Cc chc nng xem bn ,bnh lun v chia s hot ng tt.

nh gi kt qu

II.
-

Chc nng ti nh v bnh lun con hi chm

Giao din i vi ngi mi dng cn hi kh s dng

C s d liu cn t,thng tin cha chnh xc

Cc chc nng bn i lc cn li xc nh v tr hin ti.

Hng pht trin

III.
-

Hon thin li cc chc nng bn ,thit k giao din bt mt,thn thin vi ngi
s dng hn.

Xy dng chc nng ng b hai chiu ngi dng c th trc tip cp nht qun
n t in thoi.

Pht trin ng dng cho cc thnh ph khc,thu thp c s d liu nhiu v chnh
xc hn.

SVTH: Ha Bch Trung Lp 11TLT

Trang 47

PH LC
Mi trng v cng c s dng pht trin ng dng
Mi trng pht trin ng dng

STT
1

M t

Tn
H iu hnh di ng

Android 2.2 hoc cao hn

Cng c s dng pht trin ng dng

STT

Tn

M t

Eclipse

Cng c lp trnh Android

SQLite Manager

Tin ch trn FireFox gip qun l


c s d liu sqlite

TI LIU THAM KHO


[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]

Grant Allen,Mark Murphy.Beginning Android 4.2011,604tr


Satya Komatineni, Dave MacLean.Pro Android 4.2012.1020tr
Scott Davis.Google Map API,2nd edition.2006.83tr
Marko Gargenta.Learning Android.2011.268tr
Ian F. Darwin.Android Cookbook.2011.672tr

Trang web : http://developer.android.com/index.html


Trang web : http://getsocialize.com/
Trang web : http://stackoverflow.com/questions/tagged/android