huong_dan_lap_trinh_voi_android_16

Upload: nguyen-kien

Post on 08-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 huong_dan_lap_trinh_voi_android_16

    1/7

    xong s dng Explicit, gi n lt Implicit Intent. Trc khi i vo v d, hydo qua 1 cht kin thc v Intent Filter v vai tr ca n.

    Intent Filter l gActivity, Service v BroadCast Receiver s dng Intent Filter thng bo cho hthng bit cc dng Implicit Intent m n c th x l. Ni cch khc, Intent Filterl b lc Intent, ch cho nhng Intent c php i qua n.

    Intent Filter m t kh nng ca component nh ngha n. Khi h thng bt c 1Implicit Intent (ch cha 1 s thng tin chung chung v action, data v category...),n s s dng nhng thng tin trong Intent ny, kim tra i chiu vi Intent Filterca cc component cc ng dng, sau quyt nh khi chy ng dng no thchhp nht x l Intent bt c. Nu c 2 hay nhiu hn ng dng thch hp,ngi dng s c la chn ng dng mnh mun.

    VD:

    M:

    Trn l 1 Activity vi b lc Intent cho php bt v x l cc Intent gi SMS. Hylu t khaM:

    andoid:scheme

  • 8/7/2019 huong_dan_lap_trinh_voi_android_16

    2/7

    T kha ny cho bit protocol (lut) x l d liu trong URI. Ni 1 cch ngin th n l kiu ca d liu. 1 s kiu khc nh http, https, fpt, content...

    Using Implicit Intent:Yu cu:Xy dng chng trnh nhp s v gi. Lu chng trnh ca mnh y ch xy dng n mc khi nhn nt Call ca di ng th s chy ng dng vhin th giao din cho php nhp s. Phn gi dnh cho ai yu thch tm hiu thm^_^ Phn ny khng h kh nhng y mnh ch mun minh ha Implicit Intentnn s khng a vo.

    B1:Khi to project: File -> New -> Android ProjectProject name: Implicit Intent Example

    Build Target: Chn Android 1.5Application name: Implicit Intent ExamplePackage name: at.exam

    Create Activity: Example

    => Kch nt Finish.

    B2:y l bc quan trng nht v cng l bc c ngha duy nht trong cproject ny, cc bc cn li ch l bc ru ria m mnh thm vo cho ci projectn ra hn 1 cht. Bc ny s thm 1 b lc Intent Filter vo cho activity Exampleca chng ta bt s kin nhn nt Call ca di ng-> Vo AndroidManifest.xml chnh sa nh sau:M:

  • 8/7/2019 huong_dan_lap_trinh_voi_android_16

    3/7

    Thc cht ch l b sung thm dng ch mnh nh du thi ^_^

    B3:Xy dng giao din trong main.xml, bc ny ko quan trng, ch l ru ria choactivity c ci giao din:M:

  • 8/7/2019 huong_dan_lap_trinh_voi_android_16

    4/7

  • 8/7/2019 huong_dan_lap_trinh_voi_android_16

    5/7

    android:id="@+id/button4"android:layout_width="80px"android:layout_height="80px"android:gravity="center"

    android:text="4"android:textSize="25px"

    />

  • 8/7/2019 huong_dan_lap_trinh_voi_android_16

    6/7

    android:layout_height="80px"android:gravity="center"android:text="8"android:textSize="25px"

    />

  • 8/7/2019 huong_dan_lap_trinh_voi_android_16

    7/7

    android:text="Clear"android:textSize="25px"

    />

    LinearLayout cha 1 TextView hin th s nhn, 1 TableLayout c cc Buttontng ng vi cc s v 1 Button clear cho TextView.