Tim hieu lap trinh

Click here to load reader

  • date post

    29-Dec-2015
  • Category

    Documents

  • view

    177
  • download

    2

Embed Size (px)

description

Tài liệu tham khảo tìm hiểu về lập trình Android

Transcript of Tim hieu lap trinh

  • 1

    TRNG I HC BCH KHOA H NI

    Vin Cng ngh Thng tin v Truyn thng

    BO CO N 2

    ti:

    Tm hiu h iu hnh Android v xy dng ng dng

    minh ha

    Gio vin hng dn: ThS. Lng Mnh B

    Sinh vin thc hin:

    1. L c Anh SHSV: 20109202

    2. Nguyn Vn Bo SHSV: 20109209

    3. Bi Vn Chin SHSV: 20109214

    H NI 11/2012

  • 2

    MC LC I- M U .......................................................................................................................................... 4

    II- H IU HNH ANDROID. .......................................................................................................... 4

    1. Gii thiu chung ................................................................................................................................ 4

    2. Kin trc h iu hnh Android ........................................................................................................ 4

    III- PHT TRIN NG DNG CHO H IU HNH ANDROID. .............................................. 6

    1. Tng quan ng dng Android ........................................................................................................... 6

    2. Mi trng, cng c h tr pht trin ............................................................................................... 6

    2.1. Mi trng pht trin .................................................................................................................... 6

    2.2. Ci t plugin ADT cho Eclipse ................................................................................................... 7

    2.3. Ci t Android SDK .................................................................................................................... 8

    2.4. Ci t SDK APIs ......................................................................................................................... 9

    2.5. Ci t AVD s dng AVD Manager ......................................................................................... 10

    2.6. Cng c g ri DDMS (Dalvik Debug Monitor Server) ............................................................ 12

    2.7. Ci t AVD s dng dng lnh ................................................................................................. 13

    2.8. S dng Android Emulator ......................................................................................................... 14

    2.8.1. Ci t ng dng vo Emulator .............................................................................................. 14

    2.8.2. Lm vic vi Disk images trong Emulator .............................................................................. 16

    2.8.3. Emulator Networking .............................................................................................................. 16

    2.8.4. S dng Emulator Console ..................................................................................................... 18

    3. Pht trin ng dng trn Android.................................................................................................... 23

    3.1. To chng trnh Hello World .................................................................................................... 24

    3.2. Thnh phn giao din trong Android .......................................................................................... 30

    3.2.1. View: ....................................................................................................................................... 30

    3.2.2. ViewGroup : ............................................................................................................................ 30

    3.2.3. Mt s thnh phn giao din thng dng ................................................................................ 30

    3.2.3.1. Button: ................................................................................................................................. 30

    3.2.3.2. ImageButton: ....................................................................................................................... 31

    3.2.3.3. ImageView: ......................................................................................................................... 31

    3.2.3.4. TextView: ............................................................................................................................ 31

    3.2.3.5. EditText: .............................................................................................................................. 32

    3.2.3.6. CheckBox: ........................................................................................................................... 32

    3.2.3.7. RadioButton v RadioGroup: ............................................................................................. 33

  • 3

    3.2.3.8. ListView: ............................................................................................................................. 34

    3.2.3.9. AutoCompleteTextView: ...................................................................................................... 35

    3.2.3.10. Menu Options: .................................................................................................................... 36

    3.2.3.11. ProgressBar: ....................................................................................................................... 37

    3.3. Thao tc vi lung ...................................................................................................................... 39

    3.4. Thao tc c s d liu s dng SQLite ....................................................................................... 41

    3.5. Activity v Intent ........................................................................................................................ 43

    3.6. B nh chia s ............................................................................................................................. 45

    3.6.1. Shared Preferences ................................................................................................................. 45

    3.6.2. Internal Storeage: ................................................................................................................... 47

    3.6.3. External Storeage .................................................................................................................... 48

    IV- NG DNG MINH HA .......................................................................................................... 49

    V- KT LUN ................................................................................................................................. 55

    VI- TI LIU THAM KHO........................................................................................................... 56

  • 4

    I- M U

    Hin nay, nhu cu s dng cc thit b di ng ngy cng ln, ko theo s pht trin ca cc nn tng di ng. Trn th trng c rt nhiu h iu hnh di ng nh iOS, Window Phone, BlackBerry, Symbian, LiMo, ... Trong , ni bt phi k n l h iu hnh Android. Vi c tnh l nn tng m ngun m v hon ton min ph, Android to nhiu thun li cho cc nh pht trin thit k ng dng di ng ca mnh, gip nn tng ny ngy cng pht trin hn na..

    II- H IU HNH ANDROID.

    1. Gii thiu chung

    Android l b cng c phn mm m ngun m da trn nhn Linux 2.6 dnh cho nn tng di ng c pht trin bi Google v Open Handset Alliance (t chc a quc gia do Google lp, nhm xy dng mt chic in thoi tt hn da trn Android). Hng trm triu thit b Android trn ton cu hin nay minh chng cho s pht trin mnh m ca nn tng ny.

    Nhng c tnh ni tri ca h iu hnh Android so vi cc h iu hnh di ng khc:

    Android thc s m, mt nn tng pht trin da trn Linux v m ngun m: Cc nh sn xut thit b v cc nh pht trin yu thch Android do h c th s dng v ty chnh n m khng phi tr tin bn quyn.

    Cung cp cc dch v nn tng pht trin ng dng.

    H tr ngn ng lp trnh Java, C/C++.

    D dng xy dng, chnh sa, nng cp ng dng.

    Ti u ha cho cc thit b vi ngun nng lng thp v b nh hn ch.

    ha v m thanh cht lng cao.

    Tng thch vi nhiu kin trc phn cng khc nhau.

    c h tr mnh m t Google..

    2. Kin trc h iu hnh Android

  • 5

    Linux Kernel: Android c xy dng da trn nhn Linux v l mt h iu hnh a nhim thc s. Nhn Linux cung cp tng o ha phn cng cho Android, gip Android c th thch hp vi a dng nn tng phn cng.

    Libraries: Cc th vin chia s ton b c vit bng C/C++, c bin dch ph hp vi c th kin trc phn cng s dng bi cc thit b di ng, c ci t sn bi nh sn xut. Mt s th vin quan trng nh:

    Surface Manager: Qun l ca s, hin th, hiu ng.

    2D, 3D Graphics: Th vin ha s dng phn cng 3D (nu c) v cng c h tr nhanh (nu khng).

    Media codecs: Android chi c nhiu nh dng video v m thanh nh: AAC, AVC, H.263, MP3, MP4...

    SQLite database: Cng c c s d liu gn nh.

    Browser engine: h tr xy dng ng dng duyt web, Android s dng Webkit libraries.

    Android Runtime: gm th vin li Java, my o Dalvik (ti u ha cho b nh hn ch, cho php nhiu VM chy ng thi v to thun li cho h iu hnh li (Linux) trong bo mt v c lp gia cc tin trnh)

    Application Framework: tng ny cung cp thnh phn cp cao to ng dng, mc nh c ci sn, nhng nh pht trin c th k tha bng nhng thnh phn ca mnh. Mt s thnh phn quan trng:

  • 6

    Activity manager: iu khin vng i ng dng.

    Content providers: nhng i tng d liu c ng gi cn thit chia s gia cc ng dng (v d nh l danh b)

    Resource manager: qun l ti nguyn ca ng dng (nhng th khng phi l code nh xu k t, hnh nh, m thanh...)

    Location manager: cho php xc nh v tr thit b da vo GPS v Google Maps.

    Notification manager: qun l thng bo n ngi dng