Android Book.doc

Embed Size (px)

Citation preview

  • 8/22/2019 Android Book.doc

    1/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Introduction:

    Android is an Linux Based Mobile Phone Oera!in" S#s!e$% i! &asde'eloed b# !he Goo"le and announ(ed as an oen sour(e

    )OR* Android is an oen sour(e so+!&are s!a(, &hi(h (o$es &i!h anoera!in" s#s!e$% $iddle&are (o$onen!s% ,e# ali(a!ions li,e (alendar% address

    boo,% $essa"in" ali(a!ion and !he addi!ional API-s &hi(h $a,es $obileali(a!ion de'elo$en! $ore +lexible and beau!i+ul.

    Operating System:

    Oera!in" S#s!e$ is a User in!er+a(e Be!&een User and !he hard&are(o$onen!s.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e /

  • 8/22/2019 Android Book.doc

    2/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Differences between java SDK & Android SDK

    Standard Application Development Vs obile Device!ava SDK Android SDK

    Lo! o+ 0PU seed1Unli$i!ed $e$or#+or allo(a!ion

    Lo& seed 0PU% 'er# li!!le RAM

    We &ri!e (ode% (o$ile% run and debu"on !he sa$e de'i(e)0o$u!er*.

    0ode is &ri!!en and (o$ile on a P0.Bu! !he ali(a!ion runs on a se(ondar#de'i(e% !he $obile hone. Ali(a!ion%Da!a are !rans+erred !o hone durin" isdone on P0.E$ula!or is a 'ir!ual de'i(e hones on

    P0 !o seed u de'elo$en!.End user en'iron$en!% hard&are sa(e(an be di++eren!. So$e bu"s $a# o((uron In!el 0PU% Bu! no! SMF 0PUs.

    We re(isel# ,no& !he sa(es o+ !he!ar"e! de'i(es. All end users de'i(esha'e sa$e (on+i"ura!ion.

    Need no! &orr# abou! !as, riori!ies OS&ill !a,e (are.

    Phone +un(!ionali!# is riori!# 2/ on a$obile &hen !here is an in(o$in" (all%one ali(a!ion &ould be (losed or

    aused b# !he de'i(e.

    Ali(a!ion (rash is no! a ser'er issue. S!abili!# ba!!er# usa"e are 'er#

    i$or!an! our ali(a!ion should no!han" a hone. I+ user is lis!enin" !o$usi( on iPad3iPhone in ba(,"roundand runs our ali(a!ion &e $us!disable sounds in our ali(a!ion.

    No $iddle ar!# be!&een de'eloer andend1user. Users (an dire(!l# do&nloadali(a!ions +ro$ our &ebsi!es3D4Ds

    An a s!ore )Ale iTunes*% Android$ar,e! la(e are !he $iddle ar!#.Ali(a!ion (an be do&nload onl#!hrou"h !hese s!ores. An aro'ed b#a s!ories a $us! be+ore &e (ansell3hos! ali(a!ions.

    5e# board and $ouse% lar"e s(reen si6e.Ma# or $a# no! ha'e a $i(% sea,er%&eb (a$s7e!(.GPS s#s!e$ no! a'ailable e'en in la!os.

    Mul!i !ou(h s(reen5e# board $a# or $a# no! be a'ailableA((elero$e!er )!il! de!e(!ion*GPS% 0a$era% $i( and sea,er areal&a#s !here.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 8

  • 8/22/2019 Android Book.doc

    3/207

    DURGA SOFTWARE SOLUTIONSANDROID

    IPAddress is !he onl# &a# !o "i'esuser-s lo(a!ion

    Our ali(a!ion (an a((ess users (on!a(!lis!% (all his!or#7e!(.

    Android is an oen sour(e so+!&are s!a(, &hi(h (o$es &i!h an oera!in"

    s#s!e$% $iddle&are (o$onen!s% ,e# ali(a!ions li,e (alendar% address boo,%$essa"in" ali(a!ion and !he addi!ional API-s &hi(h $a,es $obile ali(a!ionde'elo$en! $ore +lexible and beau!i+ul.

    Android SD5

    Do(u$en!a!ion

    No de'elo$en! (har"es

    No li(ensin" (os!s

    No delo#$en! +ees

    De'eloers (o$$uni!#

    Versions

    /.9 1111111 : 0u(a,e/.; 1111111 : Donu!

    8.

  • 8/22/2019 Android Book.doc

    4/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Android /.; ?Android /.9 =Android /./ 8Android /.< /

    #ist ( Android ")ones in India

    A lis! o+ 'arious Android hones &hi(h are (urren!l# a'ailable in India.

    ")one *ame

    otorola

    Mo!orola Miles!one CT8T0 Ma"i(

    >T0 >ero

    >T0 Wild+ire

    >T0 Ta!!oo

    Samsung

    Sa$sun" Galax# S

    Sa$sun" Galax# Si(a

    Sa$sun" Galax# i9

  • 8/22/2019 Android Book.doc

    6/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Gar$in Asus A/T0% LG% Mo!orola% Son#Erri(sun% Bell% 0is(o% A(er% >%Tablibs.

    -ompressed 3ormatAndroid .a, S#$bian .sisIPhone .aBla(,Berr# .(od8ME .Har Windo&s .(ab

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e ;

    http://androidos.in/2010/10/garmin-asus-a10-android-phone-launched-in-india-for-rs-18990/http://androidos.in/2010/08/spice-announces-two-android-smartphones-a-tablet-for-india-market/http://androidos.in/2010/11/micromax-andro-is-the-cheapest-android-phone-in-india-at-rs-6999/http://androidos.in/2010/10/garmin-asus-a10-android-phone-launched-in-india-for-rs-18990/http://androidos.in/2010/08/spice-announces-two-android-smartphones-a-tablet-for-india-market/http://androidos.in/2010/11/micromax-andro-is-the-cheapest-android-phone-in-india-at-rs-6999/
  • 8/22/2019 Android Book.doc

    7/207

    DURGA SOFTWARE SOLUTIONSANDROID

    A*D4OID

    Android constitute t)e following components%

    >ard&are re+eren(e i$le$en!a!ion &hi(h deals &i!h hard&are

    (o$onen!s li,e 0a$era% Blue!oo!h% WiFi% Disla#% Flash% Audio%

    USB% Po&er Mana"e$en! 7e!(.

    Linux 5ernel in!e"ra!ed &i!h hard&are.

    Run!i$e En'iron$en! )54M*

    Ali(a!ion Fra$e&or, +or desi"nin" ali(a!ions

    User In!er+a(e +ra$e&or,

    Libraries.

    Na!i'e Ali(a!ions )re ins!alled ali(a!ions*.

    +ardware reference implementation:5

    Android ro'ides a se(i+i( hard&are re+eren(e i$le$en!a!ion &hi(hro'ides !he (aabili!ies !o !al, &i!h !he so+!&are or ba(,"round ser'i(es ins!all on

    !he de'i(es.#inu0 Kernel:1

    I! ro'ides basi( se! o+ libraries +or runnin" !he Android ali(a!ion. I! a(!sas a (o$$uni(a!ion (hannel be!&een !he ali(a!ions and !he hard&are(o$onen!s.4untime .nvironment:1

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e

  • 8/22/2019 Android Book.doc

    8/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Android ali(a!ion run in a seara!e re o&n run!i$e en'iron$en! &hi(his (alled Dalvi6 Virtual ac)ine 7DV8%

    Application 3ramewor6:1

    Ali(a!ion +ra$e&or, ro'ides a &a# !o exose !he ser'i(es &hi(h !heoera!in" s#s!e$ is ro'idin" li,e 0on!en! Pro'iders% da!abases% A(!i'i!#Mana"er% Pa(,a"e Mana"er% Sensor Mana"er% No!i+i(a!ion Mana"er% Resour(es%Lo(a!ion Mana"er% Telehon# Mana"er% 4ie& s#s!e$ 7. E!(.

    9ser Interface 3ramewor6:1A UI +ra$e&or, allo&s !he ali(a!ion de'eloers !o de'elo user s(reens

    in a $ore "rahi(al ri(h &a#.

    #ibrariesA"I:1I! &ill ro'ide basi( libraries and API-s &hi(h aids in !he de'elo$en!

    ro(ess o+ !he ali(a!ion.

    "re5Installed Applications:5

    Android s!a(, (o$es &i!h !he se! o+ re1ins!alled ali(a!ions li,e 0alendar%0on!a(! boo, 7 e!(.

    Applications comes wit) Android ")one

    The na!i'e ali(a!ions &hi(h (o$e alon" side &i!h !he android oera!in" s#s!e$are de'i(e +irs!.

    /. Android $ar,e!

    8. Bro&ser )Web,i! en"ine based bro&ser*

    =. E1$ail (lien!3ali(a!ions )G$ail a((oun! b# de+aul!*.

    ?. Wid"e!s3"a$es3(alendar 7

    9. Media Pla#er;. Pi(!ure 4ie&er

    . PIM da!abase ali(a!ions

    . GPS )Global Posi!ionin" S#s!e$* Goo"le Mas.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e

  • 8/22/2019 Android Book.doc

    9/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Android ar6et:1I! is a (en!ral reosi!or# &here !housands o+ android ali(a!ions (an be

    do&nloaded a! +ree o+ (os!.;rowser:1

    The bro&ser runs on 1eb6itbased en"ine..5mail -lient:1

    Personal e1$ail a((oun!s (an be (on+i"ured in a hone usin" !he e1$ail(lien!.1idgets:1

    A nu$ber o+ "a$in" ali(a!ions and u!ili!ies are shied &i!h !he de'i(es.edia "layer:1

    A Media Pla#er &ill be ro'ided b# de+aul! &hi(h suor!s 'ariousaudio3'ideo +or$a!s li,e .$=% .$?% .&a' +iles.

    "icture Viewer:1A de+aul! i(!ure 'ie&er ali(a!ion &ill (o$e &i!h suor!s di++eren!

    "rahi(al +or$a!s li,e %png% .H" 7 )%png is re+erred*"I database:1 )"ersonal Information anagement*

    The PIM da!abase ro'ides !he se(ial!# !o s!ore (alendar and ersonale1$ail a((oun!./"S 7/lobal "ositioning System8 5 /oogle aps:5

    Androoid ro'ides GPS ser'i(es +or a((essin" Goo"le Mas.

    SS ased Applications:1The de+aul! SMS ali(a!ions &ill allo& #ou !o send and re(ei'e $essa"es

    3eatures

    Application framewor6enablin" reuse and rela(e$en! o+ (o$onen!s Dalvi6 virtual mac)ineo!i$i6ed +or $obile de'i(es Integrated browserbased on !he oen sour(e Web5i!en"ine Optimi.8;?% MP=% AA0% AMR% PG% PNG% GIF* /S ,elep)ony)hard&are deenden!* ;luetoot)> .D/.> ?/> and 1i3i)hard&are deenden!* -amera> /"S> compass> and accelerometer)hard&are deenden!*

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e @

    http://webkit.org/http://webkit.org/
  • 8/22/2019 Android Book.doc

    10/207

    DURGA SOFTWARE SOLUTIONSANDROID

    4ic) development environmentin(ludin" a de'i(e e$ula!or% !ools +ordebu""in"% $e$or# and er+or$an(e ro+ilin"% and a lu"in +or !he E(liseIDE

    Android Arc)itecture

    The +ollo&in" dia"ra$ sho&s !he $aHor (o$onen!s o+ !he Android oera!in"s#s!e$. Ea(h se(!ion is des(ribed in $ore de!ail belo&.

    Applications

    Android &ill shi &i!h a se! o+ (ore ali(a!ions in(ludin" an e$ail (lien!% SMSro"ra$% (alendar% $as% bro&ser% (on!a(!s% and o!hers. All ali(a!ions are&ri!!en usin" !he a'a ro"ra$$in" lan"ua"e.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e /

  • 8/22/2019 Android Book.doc

    11/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Application 3ramewor6

    B# ro'idin" an oen de'elo$en! la!+or$% Android o++ers de'eloers !he abili!#!o build ex!re$el# ri(h and inno'a!i'e ali(a!ions. De'eloers are +ree !o !a,e

    ad'an!a"e o+ !he de'i(e hard&are% a((ess lo(a!ion in+or$a!ion% run ba(,"roundser'i(es% se! alar$s% add no!i+i(a!ions !o !he s!a!us bar% and $u(h% $u(h $ore.

    De'eloers ha'e +ull a((ess !o !he sa$e +ra$e&or, APIs used b# !he (oreali(a!ions. The ali(a!ion ar(hi!e(!ure is desi"ned !o si$li+# !he reuse o+(o$onen!sJ an# ali(a!ion (an ublish i!s (aabili!ies and an# o!her ali(a!ion$a# !hen $a,e use o+ !hose (aabili!ies )subHe(! !o se(uri!# (ons!rain!s en+or(ed

    b# !he +ra$e&or,*. This sa$e $e(hanis$ allo&s (o$onen!s !o be rela(ed b#!he user.

    Underl#in" all ali(a!ions is a se! o+ ser'i(es and s#s!e$s% in(ludin"K

    A ri(h and ex!ensible se! o+ 4ie&s!ha! (an be used !o build an ali(a!ion%in(ludin" lis!s% "rids% !ex! boxes% bu!!ons% and e'en an e$beddable &eb

    bro&ser 0on!en! Pro'iders !ha! enable ali(a!ions !o a((ess da!a +ro$ o!her

    ali(a!ions )su(h as 0on!a(!s*% or !o share !heir o&n da!a A Resour(e Mana"er% ro'idin" a((ess !o non1(ode resour(es su(h as

    lo(ali6ed s!rin"s% "rahi(s% and la#ou! +iles ANo!i+i(a!ion Mana"er!ha! enables all ali(a!ions !o disla# (us!o$

    aler!s in !he s!a!us bar An A(!i'i!# Mana"er!ha! $ana"es !he li+e(#(le o+ ali(a!ions and

    ro'ides a (o$$on na'i"a!ion ba(, s!a(,

    #ibraries

    Android in(ludes a se! o+ 030 libraries used b# 'arious (o$onen!s o+ !heAndroid s#s!e$. These (aabili!ies are exosed !o de'eloers !hrou"h !he Androidali(a!ion +ra$e&or,. So$e o+ !he (ore libraries are lis!ed belo&K

    System - library1 a BSD1deri'ed i$le$en!a!ion o+ !he s!andard 0s#s!e$ librar# )lib(*% !uned +or e$bedded Linux1based de'i(es

    edia #ibraries1 based on Pa(,e!4ideos Oen0OREJ !he librariessuor! la#ba(, and re(ordin" o+ $an# oular audio and 'ideo +or$a!s%as &ell as s!a!i( i$a"e +iles% in(ludin" MPEG?% >.8;?% MP=% AA0% AMR%PG% and PNG

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e //

    http://developer.android.com/resources/tutorials/views/index.htmlhttp://developer.android.com/guide/topics/providers/content-providers.htmlhttp://developer.android.com/guide/topics/resources/resources-i18n.htmlhttp://developer.android.com/reference/android/app/NotificationManager.htmlhttp://developer.android.com/reference/android/app/Activity.htmlhttp://developer.android.com/resources/tutorials/views/index.htmlhttp://developer.android.com/guide/topics/providers/content-providers.htmlhttp://developer.android.com/guide/topics/resources/resources-i18n.htmlhttp://developer.android.com/reference/android/app/NotificationManager.htmlhttp://developer.android.com/reference/android/app/Activity.html
  • 8/22/2019 Android Book.doc

    12/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Surface anager1 $ana"es a((ess !o !he disla# subs#s!e$ andsea$lessl# (o$osi!es 8D and =D "rahi( la#ers +ro$ $ul!ile ali(a!ions

    #ib1eb-ore1 a $odern &eb bro&ser en"ine &hi(h o&ers bo!h !heAndroid bro&ser and an e$beddable &eb 'ie&

    S/#1 !he underl#in" 8D "rahi(s en"ine ?D libraries1 an i$le$en!a!ion based on OenGL ES /.< APIsJ !he

    libraries use ei!her hard&are =D a((elera!ion )&here a'ailable* or !hein(luded% hi"hl# o!i$i6ed =D so+!&are ras!eri6er

    3ree,ype1 bi!$a and 'e(!or +on! renderin" S=#ite1 a o&er+ul and li"h!&ei"h! rela!ional da!abase en"ine a'ailable !o

    all ali(a!ions

    Android 4untime

    Android in(ludes a se! o+ (ore libraries !ha! ro'ides $os! o+ !he +un(!ionali!#a'ailable in !he (ore libraries o+ !he a'a ro"ra$$in" lan"ua"e.

    E'er# Android ali(a!ion runs in i!s o&n ro(ess% &i!h i!s o&n ins!an(e o+!he Dal'i, 'ir!ual $a(hine. Dal'i, has been &ri!!en so !ha! a de'i(e (an run$ul!ile 4Ms e++i(ien!l#. The Dal'i, 4M exe(u!es +iles in !he Dal'i, Exe(u!able).dex* +or$a! &hi(h is o!i$i6ed +or $ini$al $e$or# +oo!rin!. The 4M isre"is!er1based% and runs (lasses (o$iled b# a a'a lan"ua"e (o$iler !ha! ha'e

    been !rans+or$ed in!o !he .dex +or$a! b# !he in(luded dx !ool.

    The Dal'i, 4M relies on !he Linux ,ernel +or underl#in" +un(!ionali!# su(h as!hreadin" and lo&1le'el $e$or# $ana"e$en!.

    #inu0 Kernel

    Android relies on Linux 'ersion 8.; +or (ore s#s!e$ ser'i(es su(h as se(uri!#%$e$or# $ana"e$en!% ro(ess $ana"e$en!% ne!&or, s!a(,% and dri'er $odel. The,ernel also a(!s as an abs!ra(!ion la#er be!&een !he hard&are and !he res! o+ !heso+!&are s!a(,.

    Android Application #ife -ycle

    Android run !i$e en'iron$en! &ill $ana"e !he Resour(es and !he li+e (#(le

    o+ !he ali(a!ion% android ali(a!ion has no (on!rol o'er !heir o&n li+e(#(le. Android ali(a!ion (o$onen!s !ra(, !he s!a!e o+ !he ali(a!ion and!he# rea(! in a roer $anner.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e /8

  • 8/22/2019 Android Book.doc

    13/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Android $ana"ed resour(es in su(h a &a# !ha! !he ali(a!ion re$inds

    resonsi'e +or !he end users. The $ana"e$en! o+ !he resour(es is based onriori!i6a!ion ro(ess.

    Application priority1

    The riori!# o+ !he hos!ed ali(a!ions de!er$ines !he ro(ess in &hi(h% !hero(esses are ,illed and !he resour(es are !a,en ba(,. The riori!# o+ anali(a!ion is eual !o !he hi"hes! riori!# (o$onen!.

    When !&o ali(a!ions are ha'in" !he sa$e riori!# !he ro(ess% !ha! &ass!a#in" +or a lon"er !i$e &ill be ,illed +irs!.

    In !he (ase o+ in!er ro(ess (o$$uni(a!ion i+ an ali(a!ion is deenden! on!he ser'i(e o++ered b# o!her ali(a!ion% !he o!her ali(a!ion &ill ha'e !he sa$eriori!# as !he +irs! ali(a!ion &hi(h is o++erin" !he ser'i(e.

    States of t)e process:5

    /. A(!i'e ro(ess )>i"hes! riori!# ExK1 Galler#*8. 4isible ro(ess )>i"h se(ond riori!# ExK1 Dialo" Box*=. S!ar!ed ser'i(e ro(ess )>i"h se(ond riori!# ExK1 4ideo s!ar!ed bu! no!

    'isible*?. Ba(,"round ro(ess )Lo& riori!# ExK1 Media la#er*

    9. E$!# ro(ess )Lo& riori!# Ex K1 Se(ond !i$e a((essin" ali(a!ion*111:The old ins!an(e is s!ores in !he e$!# ro(ess.

    Active process:1

    A(!i'e ro(ess or Fore"round ro(ess is !he ali(a!ion &i!h

    (o$onen!s (urren!l# in!era(!in" &i!h !he user. This ro(ess &ill berunnin" in a +e& nu$ber and !he# &ill be ,illed a! !he las! riori!#.A(!i'e ro(ess or Ser'i(e or Ba(,"round ro(ess &hi(h are (urren!l#exe(u!in" re(ei'in" e'en! handlers.

    Ser'i(es !ha! are exe(u!in" onS!ar!)*%on0rea!e)* and onDes!ro#)*e'en! handlers also (o$e under A(!i'e ro(ess.

    Visible process:1

    These are !he ro(esses !ha! &ill be runnin" 'isible a(!i'i!ies.

    I! is !he a(!i'i!ies &hi(h &ill no! be resonsible !o user e'en!s.

    ExK 1 A+!er (all end &e "e! !he balan(e a$oun!7

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e /=

  • 8/22/2019 Android Book.doc

    14/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Started service process:1

    These are !he ro(esses &hi(h &ill be hos!ed ser'i(es !ha! ha'e been

    s!ar!ed.These ro(esses are (onsidered !o be +ore"round ro(ess and !he# &ill no! be

    ,illed unless resour(es are needed +or a(!i'e or 'isible ro(ess.;ac6ground process:1

    These are !he ro(esses &hi(h are no! 'isible and &hi(h don-! ha'e ser'i(es

    runnin" in !he ba(,"round. Android run!i$e $ana"e$en! &ill ,ill !hero(ess usin" a las!1seen1+irs!1,illed )ls+,* a!!ern or LRU )Las! re(en!l#used*.

    .mpty process:1

    Android de+ines !he ali(a!ions in !he $e$or# e'en a+!er !he# rea(h% !he#

    end o+ !he li+e !i$e. Android $ain!ains !his !o i$ro'e !he s!ar!u !i$e !o

    !he ali(a!ions. When !he# are re1laun(hed3re1s!ar!ed. These b# !he androidrun!i$e en'iron$en! &hene'er reuired.

    #ife -ycle of an Activity

    4isible li+e !i$eonS!ar!)* !o onS!o)*.

    Fore"round li+e !i$eonResu$e)* !o onPause)*.

    En!ire li+e !i$eon0rea!e)* !o onDes!ro#)*.

    An Activity comprises of ? states%

    /. Active or 4unning state:5 &hen !he a(!i'i!# is in !he +ore"round disla# on

    s(reen. The a(!i'i!ies &ill also in!era(!in" &i!h !he user in !his s!a!e.8. "aused State:5

    The A(!i'i!# &ill be s!ill 'isible !o !he user bu! !he user &ill no! bein!era(!in" &i!h !he a(!i'i!#. Ano!her A(!i'i!# &ill be resen! on !o o+ !hisa(!i'i!#.

    A aused A(!i'i!# is (o$le!el# ali'e !his is $ain!ains !he s!a!e a(!i'i!# andall o!her in+or$a!ion. Bu! i! (an be ,illed b# !he s#s!e$ in !he (ase o+e?x!re$el# lo& $e$or# a((usa!ions.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e /?

  • 8/22/2019 Android Book.doc

    15/207

    DURGA SOFTWARE SOLUTIONSANDROID

    =. Stopped State:5 An a(!i'i!# is said !o be in !he s!oed s!a!e &hen i! is(o$le!el# dis(arded b# ano!her a(!i'i!#% !his a(!i'i!# is no lon"er 'isible !o!he user and is o+!en ,illed b# !he $ana"er3s#s!e$ &hen $e$or# us neededon o!her a(!i'i!ies or ali(a!ions.

    .ntire #ife ,ime

    The en!ire li+e !i$e o+ !he a(!i'i!ies o+ !he a(!i'i!# a((ess be!&een !he (all !oon0rea!e)* !hrou"h a +inal (all !o onDes!ro#)* $e!hods.

    An a(!i'i!# er+or$s all i!s s!ar!u !as,s on !he (all !o on0rea!e)* $e!hod. I!releases all !he resour(es ba(, !o !he s#s!e$ !hrou"h !he (all !o onDes!ro#)*$e!hod.

    Visible #ife ,ime

    The a(!i'i!# o((urs be!&een a (all !o onS!ar!)* !hrou"h !he (all !o onS!o)*$e!hod. Durin" !his li+e !i$e !he a(!i'i!# &ill no! be in!era(!in" &i!h !he user.Be!&een !hese !&o a(!i'i!ies resour(es are $ain!ained !ha! are needed b# !hes#s!e$ !o sho& !he a(!i'i!# on !he s(reen.

    3oreground #ife ,ime

    The a(!i'i!#o((urs be!&een a (all!o onResu$e)*!hrou"h a (all !o

    onPause)* $e!hod.Durin" !his li+e !i$e!he a(!i'i!# &ill be in+ron! o+ all o!hera(!i'i!ies on !hes(reen and &ill bein!era(!in" &i!h !heend user.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e /9

  • 8/22/2019 Android Book.doc

    16/207

    DURGA SOFTWARE SOLUTIONSANDROID

    on-reate78K1This $e!hod is (alled &hen !he a(!i'i!# is +irs!buil!. A! !his s!e all !he s!ar!ua(!i'i!ies are er+or$ed !ha! are reuired b# !he a(!i'i!# in !he +or o!her s!es.

    onStart78K1

    This $e!hod is (alled Hus! be+ore !he a(!i'i!# be(o$es 'isible !o !he user. This$e!hod is +ollo&ed b# onResu$e)* $e!hod. I+ !he a(!i'i!# (o$es !o !he+ore"round or onS!o)* $e!hod% i+ i! is "oin" in!o a hidden s!a!e.

    on4esume78K1This $e!hod is (alled be+ore !he a(!i'i!# s!ar!s in!era(!in" &i!h !he user. This$e!hod is al&a#s +ollo&ed b# onPause)* $e!hod.on"ause78K1This $e!hod is (alled b# !he a(!i'i!# &hen !he s#s!e$ is abou! !o s!ar! on o!hera(!i'i!#.

    This $e!hod is used !o (o$$i! un sa'ed (han"es% s!o all !he "rahi(al userin!er+a(es &hi(h in'ol'es hea'# &ei"h! (o$onen!s or an# o!her i!e$ !ha!(onsu$es !he ro(essin" o&er &i!h !his +ollo&ed b# onResu$e)* i+ !he a(!i'i!#re!urns !o !he +ore"round or onS!o)*% i+ i! be(o$es in'isible !o !he user.

    onStop78K1

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e /;

  • 8/22/2019 Android Book.doc

    17/207

    DURGA SOFTWARE SOLUTIONSANDROID

    This $e!hod is (alled &hen !he a(!i'i!# is no lon"er 'isible !o !he end user. Thiso((urs be(a$e on o!her a(!i'i!# has been resu$ed or be(ause i! is bein" des!ro#ed.

    onDestroy78K1

    I! is (alled be+ore !he a(!i'i!ies des!ro#ed. The a(!i'i!# re(ei'es !his $e!hod as !he+inal (all be+ore i! ends.

    on4estart78K1This is (alled a+!er !he a(!i'i!# has been s!oed and be+ore i! is "e!!in" s!ar!eda"ain.

    Android includes t)e following components% ,)e developer needs to

    start developing> testing and debugging android applications%

    Android SD5

    De'elo$en! !ools

    De'i(e E$ula!or

    Do(u$en!a!ion

    Sa$le Sour(e 0ode

    Online Suor!

    Android SDK:1The +unda$en!al blo(, o+ !he Android SD5 is !he Android API3Libraries

    !ha! ro'ide de'eloer !o a((ess !he Android so+!&are s!a(, &hi(h (on!ainsdi++eren! (o$onen!s.

    Development ,ools:1

    Android SD5 ro'ides di++eren! de'elo$en! !ools !o (on'er! !he &ri!!enali(a!ions in!o exe(u!able ro"ra$s. De'elo$en! !ools also ro'ide !he+un(!ionali!# !o !es! and debu" !he de'eloed ali(a!ions.Android .mulator:1

    An E$ula!or is a +ull# interactive s6in% &hi(h ro'ides +ea!ures and+un(!ionali!# o+ si$ilar !o !hose a real de'i(e &ill be ro'idin". All android

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e /

  • 8/22/2019 Android Book.doc

    18/207

    DURGA SOFTWARE SOLUTIONSANDROID

    e$ula!ors run &i!h in !he D4M )Dal'i, 4ir!ual Ma(hine* $a,in" !he Androidali(a!ion hard&are neu!ral.

    3ull Documentation:1

    The SD5 in(ludes +ull le'el re+eren(e do(u$en!a!ion and (ode )API*do(u$en!a!ion. This $a,es !he de'elo$en! o+ !he ali(a!ion easier and a! a+as!er a(e.Do(u$en!a!ion

    0ode do(u$en!a!ion

    Re+eren(e do(u$en!a!ion

    0ode le'el do(u$en!a!ion !ells #ou &ha! is exa(!l# in(luded a! &ha! are !hea(,a"es% ea(h a(,a"e and ea(h (lass ho& #ou (an use !he$.

    Re+eren(e le'el do(u$en!a!ion de+ines ho& !o "e! s!ar!ed &i!h !he basi(ali(a!ions and !he# "i'e a (lear i(!ure o+ !he android +unda$en!als.Sample Source -ode:1

    Android SD5 in(ludes +ea!ure ri(h sa$le ali(a!ions !ha! de$ons!ra!e$an# ossible +ea!ures android ro'ides #ou.

    Online Support:1

    Android ro'ides an ex(ellen! de'eloer (o$$uni!# usin" &hi(h !hede'eloer (an build ali(a!ions in a less !i$e !a,in" !he hel o+ !he

    os!in"s3(on!a(!s on !he de'eloer (o$$uni!#.

    ,)e most important features w)ic) ma6es android differentiate from ot)er

    mobile application development platforms are: Goo"le Mas and GEO (odin"

    Ba(,"round Ser'i(es

    Da!a Sharin"

    In!er Pro(ess 0o$$uni(a!ion

    Peer1!o1Peer In!er De'i(e Ali(a!ion Messa"in"

    /oogle aps and /.O coding:1

    Goo"le Mas are in!era(!ion (o$onen!s &hi(h are ro'ided b# Goo"le !o

    si!e !he lo(a!ions on !he $a.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e /

  • 8/22/2019 Android Book.doc

    19/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Android ro'ides !he se(ial!# !o in!e"ra!e Goo"le $as &i!hin !he

    ali(a!ion and ser'i(es &e are "oin" !o de'elo.

    Goo"le Ma is an au!o$a!i( and reusable (on!rol &hi(h #ou (an use in our

    ali(a!ion.

    The $a 'ie& &id"e! le! !he users3de'eloers !o disla# and $aniula!e a

    Goo"le $a &i!hin !he a(!i'i!ies !o build $a based ali(a!ion

    Goo"le $a ali(a!ions (an be buildin" usin" !he /oogleapin!er+a(e.

    ;ac6ground Services:1

    Ba(,"round ser'i(es ro'ide a se(ial!# !o (rea!e ali(a!ion !ha!

    i$le$en!s an e'en! dri'en $odel &hi(h &or,s in !he ba(,"round &hileo!her ali(a!ions are runnin" (on!inuousl#.

    ExK 1 A s!o(, $ar,e! ali(a!ion !ha! !ra(,s !he s!o(, ri(es re"ularl# on a

    $inu!e1!o1$inu!e bases.

    ExK 1 0han"in" !he rin" !one 'olu$e deendin" on !he (urren! lo(a!ion and

    !he iden!i!# o+ (aller.

    S)ared Data:1

    Da!a (an be share be!&een !he !&o di++eren! ali(a!ions usin" !he

    $e(hanis$ o+ 0on!ex! Pro'ider.

    When an ali(a!ion (rea!es a da!abase i! is !o!all# res!ri(!ed +or use b# !ha!

    ali(a!ion i!sel+.

    The da!a (an be shared be!&een !&o di++eren! ali(a!ions b# ro'idin"

    shared er$issions b# usin" 0on!ex! Pro'ider.

    Inter "rocess -ommunication:1 Messa"es (an be ex(han"ed be!&een !&o di++eren! ali(a!ion ro(essor

    usin" In!en!s.

    "eer5to5"eer -ommunication:1

    Android o++ers eer1!o1eer $essa"in" !ha! suor! ins!an! $essa"in"%

    resen! and in!er de'i(e3in!er ali(a!ion (o$$uni(a!ion.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e /@

  • 8/22/2019 Android Book.doc

    20/207

    DURGA SOFTWARE SOLUTIONSANDROID

    In!er Ali(a!ion (o$$uni(a!ion enables !&o ali(a!ion ro(ess !o

    ex(han"e $essa"es on behal+ o+ ea(h o!her.

    In!er de'i(e (o$$uni(a!ion enables !&o ali(a!ions si!!in" on di++eren!

    de'i(es !o (o$$uni(a!e !o ea(h o!her.

    All ali(a!ions in Android are eual. Android does no! di++eren!ia!e

    be!&een na!i'e ali(a!ions and !hird ar!# ali(a!ions.

    There are !&o s(reens &hi(h (anno! be rela(ed b# !he de'eloer.

    /. User Lo(, S(reen

    8. In1(all rerie'e S(reen

    Android SDK Installation and 9sage%

    Please +ollo& !he s!es $en!ioned belo& !o ins!all Android SD5 ande(lise IDE !o "e! s!ar!ed &i!h ali(a!ion de'elo$en!.

    '% "reparing your development mac)ine

    our de'elo$en! s#s!e$ should +irs! do&nload so$e so+!&are be+ore #ou (anro"ra$ +or i!. The +irs! one is !he D5 &hi(h #ou (an do&nload +ro$h!!K33&&&.ora(le.(o$3!e(hne!&or,3Ha'a3Ha'ase3do&nloads3index.h!$l

    ou (an do&nload e(lise +ro$ here 1h!!K33&&&.e(lise.or"3do&nloads3

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 8

  • 8/22/2019 Android Book.doc

    21/207

    DURGA SOFTWARE SOLUTIONSANDROID

    ou (an use an# e(lise IDE abo'e =.? bu! #ou should al&a#s use !he la!es!'ersion.

    No!eK Ma,e sure #ou +irs! ins!all !he D5 be+ore ins!allin" !he E(lise.

    /oogle 4ecommends

    Operating Systems

    Windo&s CP )=81bi!*% 4is!a )=81 or ;?1bi!*% or Windo&s )=81 or ;?1bi!*

    Ma( OS C /ard# >eron*

    ;?1bi! dis!ribu!ions $us! be (aable o+ runnin" =81bi! ali(a!ions.

    Supported Development .nvironments

    .clipse ID.

    E(lise =.? )Gan#$ede* or =.9 )Galileo*

    -aution:There are ,no&n issues &i!h !he ADT lu"1in runnin" &i!hE(lise =.;. Please s!a# on =.9 un!il +ur!her no!i(e.

    E(lise ADT lu"in )in(luded in $os! E(lise IDE a(,a"es*

    I+ #ou need !o ins!all or uda!e E(lise% #ou (an do&nload i!

    +ro$ h!!K33&&&.e(lise.or"3do&nloads3.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 8/

    http://www.eclipse.org/downloads/http://www.eclipse.org/downloads/
  • 8/22/2019 Android Book.doc

    22/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Se'eral !#es o+ E(lise a(,a"es are a'ailable +or ea(h la!+or$. Forde'eloin" Android ali(a!ions% &e re(o$$end !ha! #ou ins!all one o+ !hese

    a(,a"esK

    E(lise IDE +or a'a EE De'eloers

    E(lise IDE +or a'a De'eloers

    E(lise +or R0P3Plu"1in De'eloers

    E(lise 0lassi( )'ersions =.9./ and hi"her*

    D5 9 or D5 ; )RE alone is no! su++i(ien!*

    Android De'elo$en! Tools lu"in )o!ional*

    No! (o$a!ible &i!h Gnu 0o$iler +or a'a )"(H*

    Ot)er development environments or ID.s

    D5 9 or D5 ; )RE alone is no! su++i(ien!*

    Aa(he An! /.;.9 or la!er +or Linux and Ma(% /. or la!er +or Windo&s

    No! (o$a!ible &i!h Gnu 0o$iler +or a'a )"(H*

    No!eK I+ D5 is alread# ins!alled on #our de'elo$en! (o$u!er% lease!a,e a $o$en! !o $a,e sure !ha! i! $ee!s !he 'ersion reuire$en!s lis!edabo'e. In ar!i(ular% no!e !ha! so$e Linux dis!ribu!ions $a# in(lude D5/.? or Gnu 0o$iler +or a'a% bo!h o+ &hi(h are no! suor!ed +or Androidde'elo$en!.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 88

  • 8/22/2019 Android Book.doc

    23/207

    DURGA SOFTWARE SOLUTIONSANDROID

    @% Downloading Android Starter pac6ageOn(e #ou ha'e #our s#s!e$ read# #ou need !o do&nload !he Android S!ar!er

    a(,a"e. The s!ar!er a(,a"e is no! a +ull de'elo$en! en'iron$en! i! in(ludesonl# !he (ore SD5 Tools% &hi(h #ou (an use !o do&nload !he res! o+ !he SD5(o$onen!s. ou (an "e! !he la!es! 'ersion o+ !he SD5 s!ar!er a(,a"e +ro$ !heLin, 1 h!!K33de'eloer.android.(o$3sd,3index.h!$l

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 8=

    http://developer.android.com/sdk/index.htmlhttp://developer.android.com/sdk/index.html
  • 8/22/2019 Android Book.doc

    24/207

    DURGA SOFTWARE SOLUTIONSANDROID

    A+!er do&nloadin"% una(, !he Android SD5 ar(hi'e !o a sa+e lo(a!ion on#our $a(hine. Ma,e a no!e o+ !he na$e and lo(a!ion o+ !he una(,ed SD5dire(!or# on #our s#s!e$ #ou &ill need !o re+er !o !he SD5 dire(!or# la!er%&hen se!!in" u !he ADT lu"1in or &hen usin" !he SD5 !ools.

    On Windo&s% ri"h!1(li(, on M# 0o$u!er% and sele(! Proer!ies. Under !heAd'an(ed !ab% hi! !he En'iron$en! 4ariables bu!!on% and in !he dialo" !ha! (o$esu% double1(li(, on Pa!h )under S#s!e$ 4ariables*. Add !he +ull a!h !o !he !ools3dire(!or# !o !he a!h.

    ?% Installing t)e AD, plug5inADT has been (rea!ed +or Android !o ease !he de'elo$en! o+ ali(a!ions usin"an in!e"ra!ed s#s!e$ +or de'elo$en!% (o$ilin" and si"nin" and !rans+errin" !o

    an android de'i(e. I! hels us ui(,l# in!e"ra!e Ha'a (ode &i!h Android API and(rea!e ali(a!ions &i!h i!. To si$li+# ADT se!u% &e re(o$$end ins!allin" !heAndroid SD5 rior !o ins!allin" ADT. When #our E(lise and Android SD5en'iron$en!s are read#% (on!inue &i!h !he ADT ins!alla!ion as des(ribed in !hes!es belo&.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 8?

  • 8/22/2019 Android Book.doc

    25/207

    DURGA SOFTWARE SOLUTIONSANDROID

    /. S!ar! E(lise% !hen sele(! +elp Install *ew Software%

    8. In !he A'ailable So+!&are dialo"% (li(, Add....=. In !he Add Si!e dialo" !ha! aears% en!er a na$e +or !he re$o!e si!e )+orexa$le% Android Plu"in* in !he Na$e +ield. In !he Lo(a!ion +ield% en!er !hisURLK h!!sK33dl1ssl."oo"le.(o$3android3e(lise3I+ #ou ha'e !rouble a(uirin" !he lu"in% #ou (an !r# usin" h!! in !he URL%ins!ead o+ h!!s )h!!s is re+erred +or se(uri!# reasons. 0li(, OK%?. Ba(, in !he A'ailable So+!&are 'ie&% #ou should no& see De'eloer Toolsadded !o !he lis!. Sele(! !he (he(,box nex! !o De'eloer Tools% &hi(h &illau!o$a!i(all# sele(! !he nes!ed !ools Android DDMS and Android De'elo$en!Tools. 0li(, Nex!.9. In !he resul!in" Ins!all De!ails dialo"% !he Android DDMS and AndroidDe'elo$en! Tools +ea!ures are lis!ed. 0li(, *e0t!o read and a((e! !he li(ensea"ree$en! and ins!all an# deenden(ies% !hen (li(, 3inis).;. Res!ar! E(lise.

    $% -onfiguring t)e AD, "lugin

    On(e #ou'e do&nloaded ADT !he nex! s!e is !o $odi+# #our ADT re+eren(es inE(lise !o oin! !o !he Android SD5 dire(!or#K/. Sele(! 1indow"references%%%!o oen !he Pre+eren(es anel)Ma( OS CK E(lise : Pre+eren(es*.8. Sele(! Android+ro$ !he le+! anel.=. For !he SD5 Lo(a!ion in !he $ain anel% (li(, ;rowse... and lo(a!e #ourdo&nloaded SD5 dire(!or#.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 89

    https://dl-ssl.google.com/android/eclipse/https://dl-ssl.google.com/android/eclipse/
  • 8/22/2019 Android Book.doc

    26/207

    DURGA SOFTWARE SOLUTIONSANDROID

    ?. 0li(, Al#% !hen OK.

    Adding Android platform

    The las! s!e is !o use A4D $ana"er !o ins!all 'arious (o$onen!s in!o #ou

    de'elo$en! en'iron$en!.

    B% #aunc)ing from .clipseAD,

    I+ #ou are de'eloin" in E(lise and ha'e alread# ins!alled !he ADT Plu"in%+ollo& !hese s!es !o a((ess !he Android SD5 and A4D Mana"er !oolK/. Oen E(lise8. Sele(! Windo& : Android SD5 and A4D Mana"er.=. Sele(! A'ailable Pa(,a"es in !he le+! anel. This &ill re'eal all o+ !he(o$onen!s !ha! are (urren!l# a'ailable +or do&nload +ro$ !he SD5 reosi!or#.?. Sele(! !he (o$onen!)s* #oud li,e !o ins!all and (li(, Ins!all Sele(!ed.9. 4eri+# and a((e! !he (o$onen!s #ou &an! and (li(, Ins!all A((e!ed. The(o$onen!s &ill no& be ins!alled in!o #our exis!in" Android SD5 dire(!ories.

    Ne& la!+or$s are au!o$a!i(all# sa'ed in!o !he Qsd,:3la!+or$s3 dire(!or#o+ #our SD5J ne& add1ons are sa'ed in !he Qsd,:3add1ons3 dire(!or#J sa$les aresa'ed in !he Qsd,:3sa$les3android1Qle'el:3J and ne& do(u$en!a!ion is sa'ed in!he exis!in" Qsd,:3do(s3 dire(!or# )old do(s are rela(ed*.

    -onfiguration

    In E(lise oen !he Pre+eren(es dialo" 'ia Windo&s 1: Pre+eren(es. Sele(! Android and$ain!ain !he ins!alla!ion a!h o+ !he Android SD5.

    I+ #ou $ain!ain !he lo(a!ion !he Android lu"in &ill re$ind #ou +reuen!l# )and +or e'er#&or,sa(e*.

    Sele(! no& 1indow1: Android SDK and AVD anager+ro$ !he $enu.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 8;

  • 8/22/2019 Android Book.doc

    27/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Sele(! a'ailable a(,a"es and sele(! !he la!es! 'ersion o+ !he SD5.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 8

  • 8/22/2019 Android Book.doc

    28/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Press Ins!all sele(!ed and (on+ir$ !he li(ense +or all a(,a"e. A+!er !he ins!alla!ion res!ar!E(lise.

    Device

    ou need !o de+ine a de'i(e &hi(h (an be used +or e$ula!ion. Press !he de'i(e $ana"er bu!!on%ress Ne& and $ain!ain !he +ollo&in".

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 8

  • 8/22/2019 Android Book.doc

    29/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Press 0rea!e A4D. This &ill (rea!e !he de'i(e. To !es! i+ #ou se!u is (orre(!% sele(! #ourde'i(e and ress S!ar!.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 8@

  • 8/22/2019 Android Book.doc

    30/207

    DURGA SOFTWARE SOLUTIONSANDROID

    -reating a +ello 1orld App for Android

    No& our s#s!e$ is read# +or &or,. S!ar! #our e(lise and (rea!e a &or, dire(!or#

    i+ no! alread# (rea!ed.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e =

  • 8/22/2019 Android Book.doc

    31/207

    DURGA SOFTWARE SOLUTIONSANDROID

    ou &ill see !he e(lise ID as sho&n in !he +i"ure belo&.

    The le+! side o+ !he UI sho&s !he roHe(!s (rea!ed b# #ou. The (en!ral UI &ill sho&!he (ode &ri!!en b# #ou and !he ri"h! end o+ !he +i"ure sho&s !he !as, lis!s. Thelo&er end o+ i! sho&s !he (onsole and lo""er &hi(h is 'er# use+ul &hiledebu""in".

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e =/

  • 8/22/2019 Android Book.doc

    32/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Steps to create +ello 1orld .0ample

    /. Oen !he e(lise IDE in a &or, sa(e and (li(,File : Ne& : O!her : Android ProHe(! and (li(, Nex!

    8. Fill !he de!ails &i!h roHe(! na$e as >ello Android. Under (on!en!s Sele(!0rea!e ne& ProHe(! in Wor,sa(e and !i(, Use De+aul! Lo(a!ion.8. Sele(! build !ar"e! as !he la!es! SD5 a'ailable. Fill in !he roer!ies as +ollo&sAli(a!ion Na$e >ello AndroidPa(,a"e Na$e or".hello.>elloAndroid

    0rea!e A(!i'i!# >elloAndroid

    0li(, Finish !o (rea!e !he roHe(! in #our &or,sa(e.

    =. ou &ill see !he +ollo&in" +iles (rea!ed au!o$a!i(all# b# !he SD5.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e =8

  • 8/22/2019 Android Book.doc

    33/207

    DURGA SOFTWARE SOLUTIONSANDROID

    A ne& a(!i'i!# Ha'a +ile "e!s (rea!ed as sho&n abo'e (on!ains !he on0rea!e)*$e!hod &hi(h is !he +irs! $e!hod !o be (alled &hen !he Ali(a!ion s!ar!s. Le! usloo, in!o !he +ile s!ru(!ure. The Mas!er +older is sa$e as Ali(a!ion na$e i! is>ello Android in our (ase. I! (on!ains +our sub+olders in(ludin" sr(% "en% res andAndroid SD5 +iles.

    src I! (on!ains !he sour(e a(,a"es and Ha'a sour(e +iles. In our sr( +older i!(urren!l# (on!ains !he a(,a"e or.hello.>elloAndroid. The a(,a"e +ur!her(on!ains !he Ha'e +ile >elloAndroid.Ha'a.

    a(,a"e or".hello.>elloAndroidJ

    i$or! android.a.A(!i'i!#J

    i$or! android.os.BundleJubli( (lass >elloAndroid ex!ends A(!i'i!#

    3 0alled &hen !he a(!i'i!# is +irs! (rea!ed. 3VO'erride

    ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e*

    suer.on0rea!e)sa'edIns!an(eS!a!e*J

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e ==

  • 8/22/2019 Android Book.doc

    34/207

    DURGA SOFTWARE SOLUTIONSANDROID

    se!0on!en!4ie&)R.la#ou!.$ain*J

    Le! us send so$e !i$e unders!andin" !he (ode !ha! "o! au!o "enera!ed. I+ #ouha'e ro"ra$$ed in Ha'a be+ore #ou (an $a,e ou! $os! o+ !he (odeabo'e.>o&e'er i+ #ou are ne& !o Ha'a and ro"ra$$in"% le! $e (lari+# +e& !hin"s +or#ou.

    The +irs! line de(lares !he a(,a"e or".hello.>elloAndroid. A a(,a"eis a na$esa(e !ha! or"ani6es a se! o+ rela!ed (lasses and in!er+a(es. So all!he +olders +or !his roHe(! &ill be (on!ained in !his a(,a"e and !he# &ill(on!ain di++eren! ele$en!s li,e i$a"es% sound +iles and Ha'a sour(e +iles.

    The nex! !&o lines are i$or!in" s!andard a(,a"es +or !he Androidse(i+i( Ha'a (ode. I$or! is !he ,e# &ord &hi(h is used !o a((ess !hes!andard and no s!andard a(,a"es inside a Ha'a +ile.

    We !hen (rea!e our (lass +elloAndroid&hi(h inheri!s !he A(!i'i!# (lass.A(!i'i!# is a s!andard (lass o+ Android &hi(h &e &ill dis(uss in de!ail a bi!la!er.

    Inside !he (lass &e de+ine a $e!hod on-reate78&hi(h is (alled &hen !he

    a(!i'i!# is s!ar!in". This is &here $os! ini!iali6a!ion haens. Theset-ontentView78 in+la!es !he a(!i'i!#-s UI and in our exa$le i! is (allin"!he $ain x$l dis(ussed belo& !o dra& !he user In!er+a(e.

    To su$ u !his (lass i$or!s s!andard de+ini!ions and (rea!e a (lass &hi(his a sub(lass o+ an A(!i'i!#. The (lass +ur!her has a $e!hod (alled ason0rea!e)* &hi(h ini!iali6es and ain!s !he UI +ro$ a $ain +ile. So no&!ha! i! $a,es sense le!s $o'e ahead.

    gen I! (on!ains !he au!o "enera!ed Ha'a +iles. As !hese +iles #ou should$a,e an# (han"es in !he$. I+ #ou $a,e (han"es in sour(e (ode !he (ode in!his +older &ill "e! $odi+ied au!o$a!i(all#.

    Android I! (on!ains !he ar!i(ular SD5 libraries bein" used +or !he(urren! roHe(!.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e =?

  • 8/22/2019 Android Book.doc

    35/207

    DURGA SOFTWARE SOLUTIONSANDROID

    res I! is one o+ !he o!her i$or!an! (on!en! +olders. I! (on!ains !hreesub+olders +or i$a"es na$el# dra&able hdi% dra&able ldi% dra&able $di. The o!her !&o sub+olders are la#ou! and 'alues. The la#ou! (on!ains!he $ain.x$l &hi(h is (alled &hen !he ali(a!ion is s!ar!ed. I+ #ou are

    +a$iliar &i!h ( or Ha'a ro"ra$$in" #ou ,no& !he +un(!ion $ain &hi(h is(alled &hene'er !he ro"ra$s +irs! s!ar!s and in a si$ilar &a# !he$ain.x$l dra&s i!s (on!en! as soon as !he ali(a!ion s!ar!s. The !rin"s.x$l(on!ained in !he 'alues +older is used !o de+ine s!rin"s !o be used &i!hin !heali(a!ions.

    #et us loo6 into t)ese two important C# files in detail%

    main%0ml

    QXx$l 'ersionY/.

  • 8/22/2019 Android Book.doc

    36/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Fro$ !he abo'e (on!en! #ou (an easil# $a,e ou! !ha! !he hello s!rin" (orresonds!o !he a(!ual s!rin" >ello World% >elloAndroid[ This is sa$e as !he ali(a!ionna$e &e "a'e.#et us now loo6 into anot)er important 0ml file created by t)e SDK for us% It

    is t)e android manifest file%

    Androidanifest%0ml

    QXx$l 'ersionY/.

  • 8/22/2019 Android Book.doc

    37/207

    DURGA SOFTWARE SOLUTIONSANDROID

    ou &ill be $a,in" (han"es in !he +our (o$onen!s and !he CML &ill "e!$odi+ied au!o$a!i(all#. Li,e i+ &e are !o add er$ission &e &ill "o !o !he

    er$ission !ab and add !he er$ission as sho&n belo&.

    -ompiling and e0ecuting our +ello 1orld%

    I! is eas# !o (o$ile !he (ode and run !he de'i(e si$ula!or asso(ia!ed &i!h !heSD5.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e =

  • 8/22/2019 Android Book.doc

    38/207

    DURGA SOFTWARE SOLUTIONSANDROID

    0li(, on !he Run As as sho&n in !he +i"ure abo'e. A sele(!ion &indo& aearsas sho&n belo&. Sele(! !he Android Ali(a!ion +ro$ i!.

    On(e #ou ress o, #our (ode &ill s!ar! (o$ilin" and #our si$ula!or &ill s!ar!.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e =

  • 8/22/2019 Android Book.doc

    39/207

    DURGA SOFTWARE SOLUTIONSANDROID

    0li(, on !he $enu ,e# on !he si$ula!or and #ou (an see !he resul! o+ !heali(a!ion.

    This exa$le o+ ours &as 'er# basi( bu! i! s!ill is a (o$le!e Android Ali(a!ionand #ou (an !a,e so$e !i$e !o "ras !he s!ru(!ure and basi( ase(!s o+ an AndroidAli(a!ion. Le! us in !he $ean!i$e !r# and $odi+# !his ro"ra$ o+ ours and u!so$e o!her !ex! in !he ou!u! s(reen.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e =@

  • 8/22/2019 Android Book.doc

    40/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Application 3undamentals

    /. Ali(a!ion 0o$onen!s/. A(!i'a!in" (o$onen!sK in!en!s8. Shu!!in" do&n (o$onen!s=. The $ani+es! +ile?. In!en! +il!ers

    Key classes

    /. A(!i'i!#8. Ser'i(e=. Broad(as!Re(ei'er?. 0on!en!Pro'ider9. In!en!

    Android ali(a!ions are &ri!!en in !he a'a ro"ra$$in" lan"ua"e. The (o$ileda'a (ode alon" &i!h an# da!a and resour(e +iles reuired b# !he ali(a!ion is bundled b# !he aapt !ool in!o anAndroid package% an ar(hi'e +ile $ar,ed b#

    an .apksu++ix. This +ile is !he 'ehi(le +or dis!ribu!in" !he ali(a!ion and

    ins!allin" i! on $obile de'i(es% !hese +ile users do&nload !o !heir de'i(es. All !he(ode in a sin"le .apk+ile is (onsidered !o be one application.

    In $an# &a#s% ea(h Android ali(a!ion li'es in i!s o&n &orldK

    B# de+aul!% e'er# ali(a!ion runs in i!s o&n Linux ro(ess. Android s!ar!s!he ro(ess &hen an# o+ !he ali(a!ions (ode needs !o be exe(u!ed% andshu!s do&n !he ro(ess &hen i!s no lon"er needed and s#s!e$ resour(es arereuired b# o!her ali(a!ions.

    Ea(h ro(ess has i!s o&n 'ir!ual $a(hine )4M*% so ali(a!ion (ode runs inisola!ion +ro$ !he (ode o+ all o!her ali(a!ions.

    B# de+aul!% ea(h ali(a!ion is assi"ned a uniue Linux user ID.Per$issions are se! so !ha! !he ali(a!ions +iles are 'isible onl# !o !ha! userand onl# !o !he ali(a!ion i!sel+ al!hou"h !here are &a#s !o exor! !he$

    !o o!her ali(a!ions as &ell.

    I!s ossible !o arran"e +or !&o ali(a!ions !o share !he sa$e user ID% in &hi(h(ase !he# &ill be able !o see ea(h o!hers +iles. To (onser'e s#s!e$ resour(es%ali(a!ions &i!h !he sa$e ID (an also arran"e !o run in !he sa$e Linux ro(ess%sharin" !he sa$e 4M.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e ?

  • 8/22/2019 Android Book.doc

    41/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Application -omponents

    A (en!ral +ea!ure o+ Android is !ha! one ali(a!ion (an $a,e use o+ele$en!s o+ o!her ali(a!ions )ro'ided !hose ali(a!ions er$i! i!*. For

    exa$le% i+ #our ali(a!ion needs !o disla# a s(rollin" lis! o+ i$a"es and ano!herali(a!ion has de'eloed a sui!able s(roller and $ade i! a'ailable !o o!hers% #ou(an (all uon !ha! s(roller !o do !he &or,% ra!her !han de'elo #our o&n. ourali(a!ion doesn! in(orora!e !he (ode o+ !he o!her ali(a!ion or lin, !o i!.Ra!her% i! si$l# s!ar!s u !ha! ie(e o+ !he o!her ali(a!ion &hen !he need arises.

    For !his !o &or,% !he s#s!e$ $us! be able !o s!ar! an ali(a!ion ro(ess&hen an# ar! o+ i! is needed% and ins!an!ia!e !he a'a obHe(!s +or !ha! ar!.There+ore% unli,e ali(a!ions on $os! o!her s#s!e$s% Android ali(a!ions don!ha'e a sin"le en!r# oin! +or e'er#!hin" in !he ali(a!ion )no main()+un(!ion% +or

    exa$le*. Ra!her% !he# ha'e essen!ial components!ha! !he s#s!e$ (an ins!an!ia!eand run as needed. There are +our !#es o+ (o$onen!sK

    Activities

    An activityresen!s a 'isual user in!er+a(e +or one +o(used endea'or!he user (an under!a,e. For exa$le% an a(!i'i!# $i"h! resen! a lis! o+$enu i!e$s users (an (hoose +ro$ or i! $i"h! disla# ho!o"rahs alon"

    &i!h !heir (a!ions. A !ex! $essa"in" ali(a!ion $i"h! ha'e one a(!i'i!#!ha! sho&s a lis! o+ (on!a(!s !o send $essa"es !o% a se(ond a(!i'i!# !o &ri!e!he $essa"e !o !he (hosen (on!a(!% and o!her a(!i'i!ies !o re'ie& old$essa"es or (han"e se!!in"s. Thou"h !he# &or, !o"e!her !o +or$ a (ohesi'euser in!er+a(e% ea(h a(!i'i!# is indeenden! o+ !he o!hers. Ea(h one isi$le$en!ed as a sub(lass o+ !he A(!i'i!#base (lass.

    An ali(a!ion $i"h! (onsis! o+ Hus! one a(!i'i!# or% li,e !he !ex!$essa"in" ali(a!ion Hus! $en!ioned% i! $a# (on!ain se'eral. Wha! !hea(!i'i!ies are% and ho& $an# !here are deends% o+ (ourse% on !he ali(a!ion

    and i!s desi"n. T#i(all#% one o+ !he a(!i'i!ies is $ar,ed as !he +irs! one !ha!should be resen!ed !o !he user &hen !he ali(a!ion is laun(hed. Mo'in"+ro$ one a(!i'i!# !o ano!her is a((o$lished b# ha'in" !he (urren! a(!i'i!#s!ar! !he nex! one.

    Ea(h a(!i'i!# is "i'en a de+aul! &indo& !o dra& in. T#i(all#% !he&indo& +ills !he s(reen% bu! i! $i"h! be s$aller !han !he s(reen and +loa! on

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e ?/

    http://developer.android.com/reference/android/app/Activity.htmlhttp://developer.android.com/reference/android/app/Activity.html
  • 8/22/2019 Android Book.doc

    42/207

    DURGA SOFTWARE SOLUTIONSANDROID

    !o o+ o!her &indo&s. An a(!i'i!# (an also $a,e use o+ addi!ional &indo&s +or exa$le% a o1u dialo" !ha! (alls +or a user resonse in !he $ids! o+!he a(!i'i!#% or a &indo& !ha! resen!s users &i!h 'i!al in+or$a!ion &hen!he# sele(! a ar!i(ular i!e$ on1s(reen.

    The 'isual (on!en! o+ !he &indo& is ro'ided b# a hierar(h# o+ 'ie&s obHe(!s deri'ed +ro$ !he base 4ie&(lass. Ea(h 'ie& (on!rols a ar!i(ularre(!an"ular sa(e &i!hin !he &indo&. Paren! 'ie&s (on!ain and or"ani6e !hela#ou! o+ !heir (hildren. Lea+ 'ie&s )!hose a! !he bo!!o$ o+ !he hierar(h#*dra& in !he re(!an"les !he# (on!rol and resond !o user a(!ions dire(!ed a!!ha! sa(e. Thus% 'ie&s are &here !he a(!i'i!#s in!era(!ion &i!h !he user!a,es la(e. For exa$le% a 'ie& $i"h! disla# a s$all i$a"e and ini!ia!e ana(!ion &hen !he user !as !ha! i$a"e. Android has a nu$ber o+ read#1$ade'ie&s !ha! #ou (an use in(ludin" bu!!ons% !ex! +ields% s(roll bars% $enui!e$s% (he(, boxes% and $ore.

    A 'ie& hierar(h# is la(ed &i!hin an a(!i'i!#s &indo& b# !heA(!i'i!#.se!0on!en!4ie&)*$e!hod. The content viewis !he 4ie& obHe(! a!!he roo! o+ !he hierar(h#.

    Services

    Aservicedoesn! ha'e a 'isual user in!er+a(e% bu! ra!her runs in !heba(,"round +or an inde+ini!e eriod o+ !i$e. For exa$le% a ser'i(e $i"h!

    la# ba(,"round $usi( as !he user a!!ends !o o!her $a!!ers% or i! $i"h! +e!(hda!a o'er !he ne!&or, or (al(ula!e so$e!hin" and ro'ide !he resul! !oa(!i'i!ies !ha! need i!. Ea(h ser'i(e ex!ends !he Ser'i(ebase (lass.

    A ri$e exa$le is a $edia la#er la#in" son"s +ro$ a la# lis!.The la#er ali(a!ion &ould robabl# ha'e one or $ore a(!i'i!ies !ha!allo& !he user !o (hoose son"s and s!ar! la#in" !he$. >o&e'er% !he $usi(

    la#ba(, i!sel+ &ould no! be handled b# an a(!i'i!# be(ause users &illexe(! !he $usi( !o ,ee la#in" e'en a+!er !he# lea'e !he la#er and be"inso$e!hin" di++eren!. To ,ee !he $usi( "oin"% !he $edia la#er a(!i'i!#

    (ould s!ar! a ser'i(e !o run in !he ba(,"round. The s#s!e$ &ould !hen ,ee!he $usi( la#ba(, ser'i(e runnin" e'en a+!er !he a(!i'i!# !ha! s!ar!ed i!lea'es !he s(reen.

    I!s ossible !o (onne(! !o )bind !o* an on"oin" ser'i(e )and s!ar! !heser'i(e i+ i!s no! alread# runnin"*. While (onne(!ed% #ou (an (o$$uni(a!e&i!h !he ser'i(e !hrou"h an in!er+a(e !ha! !he ser'i(e exoses. For !he $usi(

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e ?8

    http://developer.android.com/reference/android/view/View.htmlhttp://developer.android.com/reference/android/app/Activity.html#setContentView(android.view.View)http://developer.android.com/reference/android/app/Service.htmlhttp://developer.android.com/reference/android/view/View.htmlhttp://developer.android.com/reference/android/app/Activity.html#setContentView(android.view.View)http://developer.android.com/reference/android/app/Service.html
  • 8/22/2019 Android Book.doc

    43/207

    DURGA SOFTWARE SOLUTIONSANDROID

    ser'i(e% !his in!er+a(e $i"h! allo& users !o ause% re&ind% s!o% and res!ar!!he la#ba(,.

    Li,e a(!i'i!ies and !he o!her (o$onen!s% ser'i(es run in !he $ain

    !hread o+ !he ali(a!ion ro(ess. So !ha! !he# &on! blo(, o!her (o$onen!sor !he user in!er+a(e% !he# o+!en sa&n ano!her !hread +or !i$e1(onsu$in"!as,s )li,e $usi( la#ba(, *.

    Service .0ample

    sercice%0ml

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e ?=

  • 8/22/2019 Android Book.doc

    44/207

    DURGA SOFTWARE SOLUTIONSANDROID

    QXx$l 'ersionY/.

  • 8/22/2019 Android Book.doc

    45/207

    DURGA SOFTWARE SOLUTIONSANDROID

    ubli( (lass Ser'i(eA(!i'i!# ex!ends A(!i'i!# i$le$en!s On0li(,Lis!ener

    ri'a!e s!a!i( +inal S!rin" TAG Y Ser'i(esDe$oJ

    Bu!!on bu!!onS!ar!% bu!!onS!oJ

    VO'erride ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e*

    suer.on0rea!e)sa'edIns!an(eS!a!e*J

    se!0on!en!4ie&)R.la#ou!.ser'i(es*J

    bu!!onS!ar! Y )Bu!!on* +ind4ie&B#Id)R.id.bu!!onS!ar!*J

    bu!!onS!o Y )Bu!!on* +ind4ie&B#Id)R.id.bu!!onS!o*J

    bu!!onS!ar!.se!On0li(,Lis!ener)!his*J bu!!onS!o.se!On0li(,Lis!ener)!his*J

    ubli( 'oid on0li(,)4ie& sr(*

    s&i!(h )sr(."e!Id)**

    (ase R.id.bu!!onS!ar!K

    Lo".d)TAG% on0li(,K s!ar!in" ser'i(e*J

    s!ar!Ser'i(e)ne& In!en!)!his% M#Ser'i(e.(lass**J

    brea,J (ase R.id.bu!!onS!oK

    Lo".d)TAG% on0li(,K s!oin" ser'i(e*J

    s!oSer'i(e)ne& In!en!)!his% M#Ser'i(e.(lass**J

    brea,J

    yService%javaa(,a"e (o$.ser'i(eJ

    i$or! android.a.Ser'i(eJ

    i$or! android.(on!en!.In!en!J

    i$or! android.$edia.MediaPla#erJ

    i$or! android.os.IBinderJ

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e ?9

  • 8/22/2019 Android Book.doc

    46/207

    DURGA SOFTWARE SOLUTIONSANDROID

    i$or! android.u!il.Lo"J

    i$or! android.&id"e!.Toas!J

    ubli( (lass M#Ser'i(e ex!ends Ser'i(e

    MediaPla#er la#erJVO'erride

    ubli( IBinder onBind)In!en! in!en!*

    re!urn nullJ

    VO'erride

    ubli( 'oid on0rea!e)*

    Toas!.$a,eTex!)!his% M# Ser'i(e 0rea!ed%Toas!.LENGT>ZLONG*.sho&)*J

    la#er Y MediaPla#er.(rea!e)!his% R.ra&.robo!ro(,*J

    la#er.se!Looin")+alse*J 33 Se! looin"

    VO'erride

    ubli( 'oid onDes!ro#)*

    Toas!.$a,eTex!)!his% M# Ser'i(e S!oed%Toas!.LENGT>ZLONG*.sho&)*J

    la#er.s!o)*J

    VO'erride

    ubli( 'oid onS!ar!)In!en! in!en!% in! s!ar!id*

    Toas!.$a,eTex!)!his% M# Ser'i(e S!ar!ed%Toas!.LENGT>ZLONG*.sho&)*J

    la#er.s!ar!)*J

    Androidanifest%0ml

    QXx$l 'ersionY/.

  • 8/22/2019 Android Book.doc

    47/207

    DURGA SOFTWARE SOLUTIONSANDROID

    androidK'ersion0odeY/

    androidK'ersionNa$eY/.ER 3:

    Q3in!en!1+il!er:

    Q3a(!i'i!#:

    Qser'i(e androidKenabledY!rue androidKna$eY.M#Ser'i(e 3:

    Q3ali(a!ion: Quses1sd, androidK$inSd,4ersionY 3:

    Q3$ani+es!:

    ;roadcast receivers

    A broadcast receiveris a (o$onen! !ha! does no!hin" bu! re(ei'es andrea(!s !o broad(as! announ(e$en!s. Man# broad(as!s ori"ina!e in s#s!e$(ode +or exa$le% announ(e$en!s !ha! !he !i$e6one has (han"ed% !ha!!he ba!!er# is lo&% !ha! a i(!ure has been !a,en% or !ha! !he user (han"ed alan"ua"e re+eren(e. Ali(a!ions (an also ini!ia!e broad(as!s +or

    exa$le% !o le! o!her ali(a!ions ,no& !ha! so$e da!a has beendo&nloaded !o !he de'i(e and is a'ailable +or !he$ !o use.

    An ali(a!ion (an ha'e an# nu$ber o+ broad(as! re(ei'ers !o resond !oan# announ(e$en!s i! (onsiders i$or!an!. All re(ei'ers ex!end !heBroad(as!Re(ei'erbase (lass.

    Broad(as! re(ei'ers do no! disla# a user in!er+a(e. >o&e'er% !he# $a# s!ar!an a(!i'i!# in resonse !o !he in+or$a!ion !he# re(ei'e% or !he# $a# use !he

    No!i+i(a!ionMana"er!o aler! !he user. No!i+i(a!ions (an "e! !he usersa!!en!ion in 'arious &a#s +lashin" !he ba(,li"h!% 'ibra!in" !he de'i(e%

    la#in" a sound% and so on. The# !#i(all# la(e a ersis!en! i(on in !hes!a!us bar% &hi(h users (an oen !o "e! !he $essa"e.

    ;roadcast.0ample:5

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e ?

    http://developer.android.com/reference/android/content/BroadcastReceiver.htmlhttp://developer.android.com/reference/android/app/NotificationManager.htmlhttp://developer.android.com/reference/android/content/BroadcastReceiver.htmlhttp://developer.android.com/reference/android/app/NotificationManager.html
  • 8/22/2019 Android Book.doc

    48/207

    DURGA SOFTWARE SOLUTIONSANDROID

    AlarmActivity%java

    a(,a"e (o$.broad(as!J

    i$or! android.a.A(!i'i!#J

    i$or! android.a.Alar$Mana"erJ

    i$or! android.a.Pendin"In!en!J

    i$or! android.(on!en!.In!en!J

    i$or! android.os.BundleJ

    i$or! android.'ie&.4ie&Ji$or! android.&id"e!.Edi!Tex!J

    i$or! android.&id"e!.Toas!J

    ubli( (lass Alar$A(!i'i!# ex!ends A(!i'i!#

    VO'erride

    ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e*

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e ?

  • 8/22/2019 Android Book.doc

    49/207

    DURGA SOFTWARE SOLUTIONSANDROID

    suer.on0rea!e)sa'edIns!an(eS!a!e*J

    se!0on!en!4ie&)R.la#ou!.$ain*J

    ubli( 'oid s!ar!Aler!)4ie& 'ie&* Edi!Tex! !ex! Y )Edi!Tex!* +ind4ie&B#Id)R.id.!i$e*J

    in! i Y In!e"er.arseIn!)!ex!."e!Tex!)*.!oS!rin")**J

    In!en! in!en! Y ne& In!en!)!his% M#Broad(as!Re(ei'er.(lass*J

    Pendin"In!en! endin"In!en! Y Pendin"In!en!."e!Broad(as!)

    !his."e!Ali(a!ion0on!ex!)*%

  • 8/22/2019 Android Book.doc

    50/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Toas!.LENGT>ZLONG*.sho&)*J

    33 4ibra!e !he $obile hone

    4ibra!or 'ibra!or Y )4ibra!or*

    (on!ex!."e!S#s!e$Ser'i(e)0on!ex!.4IBRATORZSER4I0E*J

    'ibra!or.'ibra!e)8

  • 8/22/2019 Android Book.doc

    51/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Qali(a!ion androidKi(onYVdra&able3i(onandroidKlabelYVs!rin"3aZna$e:

    Qa(!i'i!# androidKna$eY.Alar$A(!i'i!#androidKlabelYVs!rin"3aZna$e:

    Qin!en!1+il!er:

    Qa(!ion androidKna$eYandroid.in!en!.a(!ion.MAIN 3:

    Q(a!e"or#androidKna$eYandroid.in!en!.(a!e"or#.LAUN0>ER 3:

    Q3in!en!1+il!er:

    Q3a(!i'i!#:

    Qre(ei'er androidKna$eYM#Broad(as!Re(ei'er3:

    Q3ali(a!ion:

    Quses1er$ission androidKna$eYandroid.er$ission.4IBRATE3:

    Q3$ani+es!:

    -ontent providers

    A content provider$a,es a se(i+i( se! o+ !he ali(a!ions da!a a'ailable !oo!her ali(a!ions. The da!a (an be s!ored in !he +ile s#s!e$% in an SLi!eda!abase% or in an# o!her $anner !ha! $a,es sense. The (on!en! ro'iderex!ends !he 0on!en!Pro'iderbase (lass !o i$le$en! a s!andard se! o+$e!hods !ha! enable o!her ali(a!ions !o re!rie'e and s!ore da!a o+ !he !#ei! (on!rols. >o&e'er% ali(a!ions do no! (all !hese $e!hods dire(!l#. Ra!her

    !he# use a 0on!en!Resol'erobHe(! and (all i!s $e!hods ins!ead. A0on!en!Resol'er (an !al, !o an# (on!en! ro'iderJ i! (ooera!es &i!h !he

    ro'ider !o $ana"e an# in!erro(ess (o$$uni(a!ion !ha!s in'ol'ed.

    Whene'er !heres a reues! !ha! should be handled b# a ar!i(ular (o$onen!%Android $a,es sure !ha! !he ali(a!ion ro(ess o+ !he (o$onen! is runnin"%

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 9/

    http://developer.android.com/reference/android/content/ContentProvider.htmlhttp://developer.android.com/reference/android/content/ContentResolver.htmlhttp://developer.android.com/reference/android/content/ContentProvider.htmlhttp://developer.android.com/reference/android/content/ContentResolver.html
  • 8/22/2019 Android Book.doc

    52/207

    DURGA SOFTWARE SOLUTIONSANDROID

    s!ar!in" i! i+ ne(essar#% and !ha! an aroria!e ins!an(e o+ !he (o$onen! isa'ailable% (rea!in" !he ins!an(e i+ ne(essar#.

    Activating components: intents

    0on!en! ro'iders are a(!i'a!ed &hen !he#re !ar"e!ed b# a reues! +ro$ a0on!en!Resol'er. The o!her !hree (o$onen!s a(!i'i!ies% ser'i(es% and

    broad(as! re(ei'ers are a(!i'a!ed b# as#n(hronous $essa"es (alled intents. Anin!en! is an In!en!obHe(! !ha! holds !he (on!en! o+ !he $essa"e. For a(!i'i!ies andser'i(es% i! na$es !he a(!ion bein" reues!ed and se(i+ies !he URI o+ !he da!a !oa(! on% a$on" o!her !hin"s. For exa$le% i! $i"h! (on'e# a reues! +or an a(!i'i!#!o resen! an i$a"e !o !he user or le! !he user edi! so$e !ex!. For broad(as!re(ei'ers% !he In!en! obHe(! na$es !he a(!ion bein" announ(ed. For exa$le% i!$i"h! announ(e !o in!eres!ed ar!ies !ha! !he (a$era bu!!on has been ressed.

    There are seara!e $e!hods +or a(!i'a!in" ea(h !#e o+ (o$onen!K

    An a(!i'i!# is laun(hed )or "i'en so$e!hin" ne& !o do* b# assin" an In!en!obHe(! !o 0on!ex!.s!ar!A(!i'i!#)*or A(!i'i!#.s!ar!A(!i'i!#ForResul!)*. Theresondin" a(!i'i!# (an loo, a! !he ini!ial in!en! !ha! (aused i! !o be laun(hed

    b# (allin" i!s "e!In!en!)*$e!hod. Android (alls !he a(!i'i!#s onNe&In!en!)*$e!hod !o ass i! an# subseuen! in!en!s.

    One a(!i'i!# o+!en s!ar!s !he nex! one. I+ i! exe(!s a resul! ba(, +ro$ !hea(!i'i!# i!s s!ar!in"% i! (alls startActivityForResult()ins!ead o+

    startActivity(). For exa$le% i+ i! s!ar!s an a(!i'i!# !ha! le!s !he user

    i(, a ho!o% i! $i"h! exe(! !o be re!urned !he (hosen ho!o. The resul! isre!urned in an In!en! obHe(! !ha!s assed !o !he (allin" a(!i'i!#sonA(!i'i!#Resul!)*$e!hod.

    A ser'i(e is s!ar!ed )or ne& ins!ru(!ions are "i'en !o an on"oin" ser'i(e* b#assin" an In!en! obHe(! !o 0on!ex!.s!ar!Ser'i(e)*. Android (alls !he ser'i(esonS!ar!)*$e!hod and asses i! !he In!en! obHe(!.

    Si$ilarl#% an in!en! (an be assed !o 0on!ex!.bindSer'i(e)*!o es!ablish anon"oin" (onne(!ion be!&een !he (allin" (o$onen! and a !ar"e! ser'i(e.The ser'i(e re(ei'es !he In!en! obHe(! in an onBind)*(all. )I+ !he ser'i(e isno! alread# runnin"% bindService()(an o!ionall# s!ar! i!.* For

    exa$le% an a(!i'i!# $i"h! es!ablish a (onne(!ion &i!h !he $usi( la#ba(,ser'i(e $en!ioned earlier so !ha! i! (an ro'ide !he user &i!h !he $eans )a

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 98

    http://developer.android.com/reference/android/content/Intent.htmlhttp://developer.android.com/reference/android/content/Context.html#startActivity(android.content.Intent)http://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent,%20int)http://developer.android.com/reference/android/app/Activity.html#getIntent()http://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent)http://developer.android.com/reference/android/app/Activity.html#onActivityResult(int,%20int,%20android.content.Intent)http://developer.android.com/reference/android/content/Context.html#startService(android.content.Intent)http://developer.android.com/reference/android/app/Service.html#onStart(android.content.Intent,%20int)http://developer.android.com/reference/android/content/Context.html#bindService(android.content.Intent,%20android.content.ServiceConnection,%20int)http://developer.android.com/reference/android/app/Service.html#onBind(android.content.Intent)http://developer.android.com/reference/android/content/Intent.htmlhttp://developer.android.com/reference/android/content/Context.html#startActivity(android.content.Intent)http://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent,%20int)http://developer.android.com/reference/android/app/Activity.html#getIntent()http://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent)http://developer.android.com/reference/android/app/Activity.html#onActivityResult(int,%20int,%20android.content.Intent)http://developer.android.com/reference/android/content/Context.html#startService(android.content.Intent)http://developer.android.com/reference/android/app/Service.html#onStart(android.content.Intent,%20int)http://developer.android.com/reference/android/content/Context.html#bindService(android.content.Intent,%20android.content.ServiceConnection,%20int)http://developer.android.com/reference/android/app/Service.html#onBind(android.content.Intent)
  • 8/22/2019 Android Book.doc

    53/207

    DURGA SOFTWARE SOLUTIONSANDROID

    user in!er+a(e* +or (on!rollin" !he la#ba(,. The a(!i'i!# &ould (allbindService()!o se! u !ha! (onne(!ion% and !hen (all $e!hods de+ined

    b# !he ser'i(e !o a++e(! !he la#ba(,.

    An ali(a!ion (an ini!ia!e a broad(as! b# assin" an In!en! obHe(! !o$e!hods li,e 0on!ex!.sendBroad(as!)*% 0on!ex!.sendOrderedBroad(as!)*%and 0on!ex!.sendS!i(,#Broad(as!)*in an# o+ !heir 'aria!ions. Androiddeli'ers !he in!en! !o all in!eres!ed broad(as! re(ei'ersb# (allin" !heironRe(ei'e)*$e!hods.

    S)utting down components

    A (on!en! ro'ider is a(!i'e onl# &hile i!s resondin" !o a reues! +ro$ a0on!en!Resol'er. And a broad(as! re(ei'er is a(!i'e onl# &hile i!s resondin" !o a

    broad(as! $essa"e. So !heres no need !o exli(i!l# shu! do&n !hese (o$onen!s.

    A(!i'i!ies% on !he o!her hand% ro'ide !he user in!er+a(e. The#re in a lon"1runnin"(on'ersa!ion &i!h !he user and $a# re$ain a(!i'e% e'en &hen idle% as lon" as !he(on'ersa!ion (on!inues. Si$ilarl#% ser'i(es $a# also re$ain runnin" +or a lon"!i$e. So Android has $e!hods !o shu! do&n a(!i'i!ies and ser'i(es in an orderl#&a#K

    An a(!i'i!# (an be shu! do&n b# (allin" i!s +inish)*$e!hod. One a(!i'i!#(an shu! do&n ano!her a(!i'i!# )one i! s!ar!ed &i!hstartActivityForResult()* b# (allin" +inishA(!i'i!#)*.

    A ser'i(e (an be s!oed b# (allin" i!s s!oSel+)*$e!hod% or b# (allin"0on!ex!.s!oSer'i(e)*.

    ,)e manifest file

    Be+ore Android (an s!ar! an ali(a!ion (o$onen!% i! $us! learn !ha! !he(o$onen! exis!s. There+ore% ali(a!ions de(lare !heir (o$onen!s in a $ani+es!+ile !ha!s bundled in!o !he Android a(,a"e% !he .apk+ile !ha! also holds !he

    ali(a!ions (ode% +iles% and resour(es.

    The $ani+es! is a s!ru(!ured CML +ile and is al&a#s na$ed AndroidMani+es!.x$l+or all ali(a!ions. I! does a nu$ber o+ !hin"s in addi!ion !o de(larin" !heali(a!ions (o$onen!s% su(h as na$in" an# libraries !he ali(a!ion needs !o belin,ed a"ains! )besides !he de+aul! Android librar#* and iden!i+#in" an#

    er$issions !he ali(a!ion exe(!s !o be "ran!ed.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 9=

    http://developer.android.com/reference/android/content/Context.html#sendBroadcast(android.content.Intent)http://developer.android.com/reference/android/content/Context.html#sendOrderedBroadcast(android.content.Intent,%20java.lang.String)http://developer.android.com/reference/android/content/Context.html#sendStickyBroadcast(android.content.Intent)http://developer.android.com/reference/android/content/BroadcastReceiver.html#onReceive(android.content.Context,%20android.content.Intent)http://developer.android.com/reference/android/app/Activity.html#finish()http://developer.android.com/reference/android/app/Activity.html#finishActivity(int)http://developer.android.com/reference/android/app/Service.html#stopSelf()http://developer.android.com/reference/android/content/Context.html#stopService(android.content.Intent)http://developer.android.com/reference/android/content/Context.html#sendBroadcast(android.content.Intent)http://developer.android.com/reference/android/content/Context.html#sendOrderedBroadcast(android.content.Intent,%20java.lang.String)http://developer.android.com/reference/android/content/Context.html#sendStickyBroadcast(android.content.Intent)http://developer.android.com/reference/android/content/BroadcastReceiver.html#onReceive(android.content.Context,%20android.content.Intent)http://developer.android.com/reference/android/app/Activity.html#finish()http://developer.android.com/reference/android/app/Activity.html#finishActivity(int)http://developer.android.com/reference/android/app/Service.html#stopSelf()http://developer.android.com/reference/android/content/Context.html#stopService(android.content.Intent)
  • 8/22/2019 Android Book.doc

    54/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Bu! !he rin(ial !as, o+ !he $ani+es! is !o in+or$ Android abou! !he ali(a!ions(o$onen!s. For exa$le% an a(!i'i!# $i"h! be de(lared as +ollo&sK

    QXx$l 'ersionY/.o&e'er% broad(as! re(ei'ers (an ei!her be de(lared in !he $ani+es!% or !he# (anbe (rea!ed d#na$i(all# in (ode )as Broad(as!Re(ei'erobHe(!s* and re"is!ered &i!h!he s#s!e$ b# (allin" 0on!ex!.re"is!erRe(ei'er)*.

    Intents

    To es!ablish (o$$uni(a!ion be!&een !&o ali(a!ions !hen &e (an use In!en!s.We (an use in!en!s

    /. S!ar!in" an a(!i'i!#

    8. Broad(as! in!en!s

    =. Ser'i(es

    There are !&o !#es o+ in!en!s./. Exli(i! In!en!s

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 9?

    http://developer.android.com/guide/topics/manifest/activity-element.htmlhttp://developer.android.com/reference/android/app/Activity.htmlhttp://developer.android.com/guide/topics/manifest/service-element.htmlhttp://developer.android.com/guide/topics/manifest/receiver-element.htmlhttp://developer.android.com/guide/topics/manifest/provider-element.htmlhttp://developer.android.com/reference/android/content/BroadcastReceiver.htmlhttp://developer.android.com/reference/android/content/Context.html#registerReceiver(android.content.BroadcastReceiver,%20android.content.IntentFilter)http://developer.android.com/guide/topics/manifest/activity-element.htmlhttp://developer.android.com/reference/android/app/Activity.htmlhttp://developer.android.com/guide/topics/manifest/service-element.htmlhttp://developer.android.com/guide/topics/manifest/receiver-element.htmlhttp://developer.android.com/guide/topics/manifest/provider-element.htmlhttp://developer.android.com/reference/android/content/BroadcastReceiver.htmlhttp://developer.android.com/reference/android/content/Context.html#registerReceiver(android.content.BroadcastReceiver,%20android.content.IntentFilter)
  • 8/22/2019 Android Book.doc

    55/207

    DURGA SOFTWARE SOLUTIONSANDROID

    8. I$li(i! In!en!s

    .0plicit Intents:5

    In!en! $#In!en!Yne& In!en!)0on!ex! %Des!ina!ion (lass*J

    s!ar!A(!i'i!#)$#In!en!*JExK1on0li(,)4ie& '*In!en! $#In!en!Yne& In!en!)"e!Ali(a!ion0on!ex!)*3Firs!A(!i'i!#.!his%Se(ondA(!i'i!#.(lass*J

    Implicit Intents:5

    In!en! $#In!en!Yne& In!en!)a(!ion% URI% Da!a*JExK1

    In!en! $#In!en!Yne& In!en!)In!en!.A0TIONZDIAL*Js!ar!A(!i'i!#)$#In!en!*J

    Trans+errin" da!a b# usin" .0tra;undle (lassI+ #ou &an! !o !rans+er !he da!a one a(!i'i!# !o ano!her a(!i'i!# !hen &e use

    u!Ex!ra),e#%'alue*J !his $e!hod has "i'en in Ex!raBundle (lasss.

    ubli( (lass Nex!A(!i'i!# ex!ends A(!i'i!#

    33our $e$ber 'ariable de(lara!ion here

    33 0alled &hen !he a(!i'i!# is +irs! (rea!ed.

    VO'erride

    ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e*

    33our (ode here

    A+!er &e ha'e (rea!ed !he ne& A(!i'i!#% &e ha'e !o re"is!er i! in +ile

    \AndroidMani+es!.x$l-.

    For re"is!erin" &e ha'e !o (rea!e an en!r# in \AndroidMani+es!.x$l- as

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 99

  • 8/22/2019 Android Book.doc

    56/207

    DURGA SOFTWARE SOLUTIONSANDROID

    Qa(!i'i!# androidKna$eY.Nex!A(!i'i!#androidKlabelYVs!rin"3aZna$e:

    Q3a(!i'i!#:

    No!e !ha! here &e ha'e no! used in!en! +il!er% sin(e &e are "oin" !o use an exli(i!

    in!en!% !he s#n!ax o+ in!en! +il!er is

    Qin!en!1+il!er:

    Qa(!ion androidKna$eYQa(!ion here:3:

    Q(a!e"or# androidKna$eYQ(a!e"or# here:3:

    Q3in!en!1+il!er:

    >ere%

    action The "eneral a(!ion !o be er+or$ed

    category Gi'es addi!ional in+or$a!ion abou! !he a(!ion !o exe(u!e. For

    exa$le% 0ATEGORZLAUN0>ER $eans i! should aear in !he Laun(her as a

    !o1le'el ali(a!ion% &hile 0ATEGORZALTERNATI4E $eans i! should bein(luded in a lis! o+ al!erna!i'e a(!ions !he user (an er+or$ on a ie(e o+ da!a.

    *oteK #ou (an also use ali(a!ion !ab belo& !heAndroidanifest%0mlE+ile% and

    in Application *odesEse(!ion (li(,

    AddEbu!!on as sho&n in +i"ure belo& and sele(! !he a(!i'i!# .

    Nex! #ou (an s!ar! !his a(!i'i!# on an# e'en! as +ollo&s

    Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);

    CurrentActivity.this.startActivity(myIntent);

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 9;

  • 8/22/2019 Android Book.doc

    57/207

    DURGA SOFTWARE SOLUTIONSANDROID

    >ere% #ou ha'e !o (rea!e and in!en! &i!h -urrentActivity%t)isas +irs! ara$e!er

    and !he !he ne0t activityas se(ond ara$e!er.

    A+!er #ou ha'e (rea!ed !he in!en!% #ou (an s!ar! !he ne& a(!i'i!# b# (allin"startActivity% on (urren! A(!i'i!#% &i!h !he (rea!ed in!en! as ara$e!er

    Different types of ActionsActivity actions

    /. A0TIONZMAIN K1 I! de+ines !he $ain en!r# oin! o+ !he a(!i'i!#.)us! li,e a$ain)* $e!hod*.

    ExK1android.in!en!.a(!ion.MAIN )!he 'alue o+ !he a!!ribu!e*.8. A0TIONZ4IEW K1 I! disla#s !he da!a !o !he user.

    android.in!en!.a(!ion.4IEW

    =. A0TIONZEDIT K1 I! ro'ides exli(i! edi!able a((ess !o !he "i'en da!a.

    ?. A0TIONZPI05 K1 I! i(,s an i!e$ +ro$ da!a. I! &ill re!urn !he sele(!edi!e$. ExK 0on!a(! Boo,111:i(,111:0ALL3DIAL

    9. A0TIONZDIAL K1 I! de+ined a nu$ber &hi(h is se(i+ied b# !he da!a. I!disla#s a user in!er+a(e &i!h !he nu$ber !o be dialed allo&in" !he user !oexli(i!l# s!ar! !he (all.

    ;. A0TIONZ0ALL K1 I! ini!ia!e a dire(! (all !o !he nu$ber se(i+ied.

    . A0TIONZANSWER K1i! handles an in(o$in" hone (all.

    . A0TIONZSEAR0> K1 I! er+or$s a sear(h oera!ion +or !he de+ined 'alue.A sear(h $ana"er is used !o sear(h !he da!a.

    @. A0TIONZDATA K1I! inser! an e$!# i!e$ in!o !he (on!ainer.

    /

  • 8/22/2019 Android Book.doc

    58/207

    DURGA SOFTWARE SOLUTIONSANDROID

    =. 0ATEGORZ0ARZDO05K1I! de+ines an a(!i'i!# !o run &hen a de'i(e isinser!ed in a (ar do(,. For (ars.

    ?. 0ATEGORZ0ARZMODEK1I! is used !o indi(a!es !ha! !he a(!ion (an be

    used in a (ar en'iron$en!.9. 0ATEGORZTABK1I! is suosed !o be used as a !ab inside a

    TabA(!i'i!#)rede+ined (lass*.

    ;. 0ATEGORZINFOK1 I! ro'ides !he In+or$a!ion abou! !he a(,a"e i! isla(ed in!o i!.

    Standard ;roadcast Actions

    /. A0TIONZBATERZ0>ANGED K1This de+ines a Brad(as! in!en!

    (on!ainin" !he (har"in" s!a!e (han"in" le'el abou! !he ba!!er#. This is$ain!ained b# !he Ba!!er# Mana"er.

    8. A0TIONZBATERZLOW K1 I! indi(a!es lo& ba!!er# (ondi!ions on !hede'i(e.ExK1 I! is a Dialo" box.

    =. A0TIONZBATERZO5K1 I! indi(a!es !he ba!!eries no& o, &i!h !he(har"in" le'el.

    ?. A0TIONZTIMEZ0>ANGEDK1 I! indi(a!es !he !i$e is se! and i! ose in aToas! $essa"e.

    +ow to create a new Android activity

    The Android de'elo$en! aradi"$ in!rodu(es +or !he de'eloer !he A(!i'i!#KQ: Durin" de'elo$en! #ou &ill +ind i! eas# !o &ra1u ar!s o+ !he +un(!ionali!#o+ #our (ode in!o indeenden! a(!i'i!ies% &i!h !heir o&n li+e (#(le. More abou!a(!i'i!# li+e (#(leon !he Android de'eloers &ebsi!e.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 9

    http://developer.android.com/reference/android/app/Activity.html#ActivityLifecyclehttp://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle
  • 8/22/2019 Android Book.doc

    59/207

    DURGA SOFTWARE SOLUTIONSANDROID

    .asy 7just start activity8

    Assu$e #ou ha'e !he MainA(!i'i!#% and a Se(ondar#A(!i'i!# #ou &an! !o s!ar!%!his $a# be done in !he easies! &a#K

    In!en! in!en! Y ne& In!en!)In!en!.A0TIONZ4IEW*Jin!en!.se!0lassNa$e)!his% Se(ondar#A(!i'i!#.(lass."e!Na$e)**Js!ar!A(!i'i!#)in!en!*J

    edium 7pass some params as well8

    No& i$a"ine #ou &an! !o ass so$e da!a !o !he ne& in!en!. ou &ill a(hie'e !hisusin" !he Bundle (lass% !o en(asula!e #our da!a.

    Exa$leK

    In!en! in!en! Y ne& In!en!)*JBundle bun Y ne& Bundle)*J

    bun.u!S!rin")ara$Zs!rin"% !he a(!ual s!rin"*J 33 add !&o ara$e!ersK a s!rin"and a boolean

    bun.u!Boolean)ara$Zbool% !rue*J

    in!en!.se!0lass)!his% Se(ondar#A(!i'i!#.(lass*Jin!en!.u!Ex!ras)bun*Js!ar!A(!i'i!#)in!en!*J

    In !he Se(ondar#A(!i'i!#% #ou &ill need !o a((ess !hese ara$s. This is ho&K

    Bundle bun Y "e!In!en!)*."e!Ex!ras)*JS!rin" ara$/ Y bun."e!S!rin")ara$Zs!rin"*J

    boolean ara$8 Y bun."e!Boolean)ara$Zbool*J

    Some useful default activities:

    Par! o+ !he beau!# o+ Android is !ha! #ou (an en(asula!e o!her+un(!ionali!#3a(!i'i!ies in #our o&n (ode% Hus! b# &ri!in" a +e& lines o+ (ode.Belo& is a lis! o+ use+ul a(!i'i!ies one $a# (onsider !o useK

    /. Wri!in" an e$ail

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e 9@

  • 8/22/2019 Android Book.doc

    60/207

    DURGA SOFTWARE SOLUTIONSANDROID

    In!en! in!en! Y ne& In!en!)In!en!.A0TIONZSENDTO%Uri.arse)$ail!oKo++i(eVexa$le.(o$**Jin!en!.u!Ex!ra)subHe(!% $# subHe(!*Jin!en!.u!Ex!ra)bod#% $# $essa"e*J

    s!ar!A(!i'i!#)in!en!*J

    8. Bro&se !o a &eb1a"e

    In!en! in!en! Y ne& In!en!)In!en!.A0TIONZ4IEW%Uri.arse)h!!K33&&&."oo"le.(o$**Js!ar!A(!i'i!#)in!en!*J

    =. Wri!e a SMS

    In!en! in!en! Y ne& In!en!)In!en!.A0TIONZSENDTO% Uri.arse)s$sK33**Jin!en!.u!Ex!ra)address% *Jin!en!.u!Ex!ra)s$sZbod#% $# $essa"e*Js!ar!A(!i'i!#)in!en!*J

    ?. Sear(h so$e!hin" on Goo"le

    In!en! in!en! Y ne& In!en!)In!en!.A0TIONZWEBZSEAR0> *Jin!en!.u!Ex!ra)Sear(hMana"er.UER% sear(h !his !ex!*Js!ar!A(!i'i!#)in!en!*J

    9. Ge! !he Wi,!ionar# o+ so$e &ord

    In!en! in!en! Y ne& In!en!)In!en!.A0TIONZ4IEW%Uri.arse)h!!K33en.&i,!ionar#.or"3&i,i3 &ord**Js!ar!A(!i'i!#)in!en!*J

    ;. Ge! !he Wi,iedia a"e o+ so$e &ords

    S!rin" uri Y h!!K33en.&i,iedia.or"3&i,i3 $# !ex!J

    In!en! in!en! Y ne& In!en!)In!en!.A0TIONZ4IEW% Uri.arse)uri**Js!ar!A(!i'i!#)in!en!*J

    Intent filters

    An In!en! obHe(! (an exli(i!l# na$e a !ar"e! (o$onen!. I+ i! does% Android+inds !ha! (o$onen! )based on !he de(lara!ions in !he $ani+es! +ile* and a(!i'a!es

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e ;

  • 8/22/2019 Android Book.doc

    61/207

    DURGA SOFTWARE SOLUTIONSANDROID

    i!. Bu! i+ a !ar"e! is no! exli(i!l# na$ed% Android $us! lo(a!e !he bes! (o$onen!!o resond !o !he in!en!. I! does so b# (o$arin" !he In!en! obHe(! !o !he intent

    filterso+ o!en!ial !ar"e!s. A (o$onen!s in!en! +il!ers in+or$ Android o+ !he,inds o+ in!en!s !he (o$onen! is able !o handle. Li,e o!her essen!ial in+or$a!ion

    abou! !he (o$onen!% !he#re de(lared in !he $ani+es! +ile. >eres an ex!ension o+!he re'ious exa$le !ha! adds !&o in!en! +il!ers !o !he a(!i'i!#K

    QXx$l 'ersionY/.

  • 8/22/2019 Android Book.doc

    62/207

    DURGA SOFTWARE SOLUTIONSANDROID

    A (o$onen! (an ha'e an# nu$ber o+ in!en! +il!ers% ea(h one de(larin" a di++eren!se! o+ (aabili!ies. I+ i! doesn! ha'e an# +il!ers% i! (an be a(!i'a!ed onl# b# in!en!s!ha! exli(i!l# na$e !he (o$onen! as !he !ar"e!.

    For a broad(as! re(ei'er !ha!s (rea!ed and re"is!ered in (ode% !he in!en! +il!er isins!an!ia!ed dire(!l# as an In!en!Fil!erobHe(!. All o!her +il!ers are se! u in !he$ani+es!.

    -reating Dialogs

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e ;8

    http://developer.android.com/reference/android/content/IntentFilter.htmlhttp://developer.android.com/reference/android/content/IntentFilter.html
  • 8/22/2019 Android Book.doc

    63/207

    DURGA SOFTWARE SOLUTIONSANDROID

    A dialo" is a s$all &indo& !ha! aears in +ron! o+ !he (urren! A(!i'i!#. Theunderl#in" A(!i'i!# loses +o(us and !he dialo" a((e!s all user in!era(!ion. Dialo"sare nor$all# used +or no!i+i(a!ions and shor! a(!i'i!ies !ha! dire(!l# rela!e !o !heali(a!ion in ro"ress.

    The Android API suor!s !he +ollo&in" !#es o+ Dialo"obHe(!sK

    Aler!Dialo"A dialo" !ha! (an $ana"e 6ero% one% !&o% or !hree bu!!ons% and3or a lis! o+sele(!able i!e$s !ha! (an in(lude (he(,boxes or radio bu!!ons. TheAler!Dialo" is (aable o+ (ons!ru(!in" $os! dialo" user in!er+a(es and is !hesu""es!ed dialo" !#e.

    Pro"ressDialo"

    A dialo" !ha! disla#s a ro"ress &heel or ro"ress bar. Be(ause i!s anex!ension o+ !he Aler!Dialo"% i! also suor!s bu!!ons.

    Da!ePi(,erDialo"A dialo" !ha! allo&s !he user !o sele(! a da!e.

    Ti$ePi(,erDialo"A dialo" !ha! allo&s !he user !o sele(! a !i$e.

    I+ #ou &ould li,e !o (us!o$i6e #our o&n dialo"% #ou (an ex!end !he base Dialo"obHe(! or an# o+ !he sub(lasses lis!ed abo'e and de+ine a ne& la#ou!.

    S)owing a Dialog

    A dialo" is al&a#s (rea!ed and disla#ed as a ar! o+ an A(!i'i!#. ou shouldnor$all# (rea!e dialo"s +ro$ &i!hin #our A(!i'i!#s on0rea!eDialo")in!*(allba(,$e!hod. When #ou use !his (allba(,% !he Android s#s!e$ au!o$a!i(all# $ana"es!he s!a!e o+ ea(h dialo" and hoo,s !he$ !o !he A(!i'i!#% e++e(!i'el# $a,in" i! !heo&ner o+ ea(h dialo". As su(h% ea(h dialo" inheri!s (er!ain roer!ies +ro$ !heA(!i'i!#. For exa$le% &hen a dialo" is oen% !he Menu ,e# re'eals !he o!ions$enu de+ined +or !he A(!i'i!# and !he 'olu$e ,e#s $odi+# !he audio s!rea$ used

    b# !he A(!i'i!#.

    *ote:I+ #ou de(ide !o (rea!e a dialo" ou!side o+ !he on0rea!eDialo")* $e!hod% i!&ill no! be a!!a(hed !o an A(!i'i!#. ou (an% ho&e'er% a!!a(h i! !o an A(!i'i!# &i!hse!O&nerA(!i'i!#)A(!i'i!#*.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e ;=

    http://developer.android.com/reference/android/app/Dialog.htmlhttp://developer.android.com/reference/android/app/AlertDialog.htmlhttp://developer.android.com/reference/android/app/ProgressDialog.htmlhttp://developer.android.com/reference/android/app/DatePickerDialog.htmlhttp://developer.android.com/reference/android/app/TimePickerDialog.htmlhttp://developer.android.com/reference/android/app/Dialog.htmlhttp://developer.android.com/reference/android/app/Activity.htmlhttp://developer.android.com/reference/android/app/Activity.html#onCreateDialog(int)http://developer.android.com/reference/android/app/Dialog.html#setOwnerActivity(android.app.Activity)http://developer.android.com/reference/android/app/Dialog.htmlhttp://developer.android.com/reference/android/app/AlertDialog.htmlhttp://developer.android.com/reference/android/app/ProgressDialog.htmlhttp://developer.android.com/reference/android/app/DatePickerDialog.htmlhttp://developer.android.com/reference/android/app/TimePickerDialog.htmlhttp://developer.android.com/reference/android/app/Dialog.htmlhttp://developer.android.com/reference/android/app/Activity.htmlhttp://developer.android.com/reference/android/app/Activity.html#onCreateDialog(int)http://developer.android.com/reference/android/app/Dialog.html#setOwnerActivity(android.app.Activity)
  • 8/22/2019 Android Book.doc

    64/207

    DURGA SOFTWARE SOLUTIONSANDROID

    When #ou &an! !o sho& a dialo"% (all sho&Dialo")in!*and ass i! an in!e"er !ha!uniuel# iden!i+ies !he dialo" !ha! #ou &an! !o disla#.

    When a dialo" is reues!ed +or !he +irs! !i$e% Android (alls on0rea!eDialo")in!*

    +ro$ #our A(!i'i!#% &hi(h is &here #ou should ins!an!ia!e !he Dialo". This(allba(, $e!hod is assed !he sa$e ID !ha! #ou assed !o sho&Dialo")in!*. A+!er#ou (rea!e !he Dialo"% re!urn !he obHe(! a! !he end o+ !he $e!hod.

    Be+ore !he dialo" is disla#ed% Android also (alls !he o!ional (allba(,$e!hod onPreareDialo")in!% Dialo"*. De+ine !his $e!hod i+ #ou &an! !o (han"ean# roer!ies o+ !he dialo" ea(h !i$e i! is oened. This $e!hod is (alled e'er#!i$e a dialo" is oened% &hereas on0rea!eDialo")in!*is onl# (alled !he 'er# +irs!!i$e a dialo" is oened. I+ #ou don! de+ine onPreareDialo")*% !hen !he dialo" &illre$ain !he sa$e as i! &as !he re'ious !i$e i! &as oened. This $e!hod is also

    assed !he dialo"s ID% alon" &i!h !he Dialo" obHe(! #ou (rea!ed inon0rea!eDialo")*.

    The bes! &a# !o de+ine !he on0rea!eDialo")in!*and onPreareDialo")in!%Dialo"*(allba(, $e!hods is &i!h aswitchs!a!e$en! !ha! (he(,s !he idara$e!er!ha!s assed in!o !he $e!hod. Ea(h caseshould (he(, +or a uniue dialo" ID and!hen (rea!e and de+ine !he rese(!i'e Dialo". For exa$le% i$a"ine a "a$e !ha!uses !&o di++eren! dialo"sK one !o indi(a!e !ha! !he "a$e has aused and ano!her !oindi(a!e !ha! !he "a$e is o'er. Firs!% de+ine an in!e"er ID +or ea(h dialo"K

    s!a!i( +inal in! DIALOGZPAUSEDZID Y

  • 8/22/2019 Android Book.doc

    65/207

    DURGA SOFTWARE SOLUTIONSANDROID

    re!urn dialo"J

    When i!s !i$e !o sho& one o+ !he dialo"s% (all sho&Dialo")in!*&i!h !he ID o+ adialo"K

    sho&Dialo")DIALOGZPAUSEDZID*J

    Dismissing a Dialog

    When #oure read# !o (lose #our dialo"% #ou (an dis$iss i!b# (allin" dis$iss)*on!he Dialo" obHe(!. I+ ne(essar#% #ou (an also (all dis$issDialo")in!*+ro$ !heA(!i'i!#% &hi(h e++e(!i'el# (alls dis$iss)*on !he Dialo" +or #ou.

    I+ #ou are usin" on0rea!eDialo")in!*!o $ana"e !he s!a!e o+ #our dialo"s )asdis(ussed in !he re'ious se(!ion*% !hen e'er# !i$e #our dialo" is dis$issed% !hes!a!e o+ !he Dialo" obHe(! is re!ained b# !he A(!i'i!#. I+ #ou de(ide !ha! #ou &ill nolon"er need !his obHe(! or i!s i$or!an! !ha! !he s!a!e is (leared% !hen #ou should(all re$o'eDialo")in!*. This &ill re$o'e an# in!ernal re+eren(es !o !he obHe(! andi+ !he dialo" is sho&in"% i! &ill dis$iss i!.

    9sing dismiss listeners

    I+ #oud li,e #our al(a!ion !o er+or$ so$e ro(edures !he $o$en! !ha! a dialo"is dis$issed% !hen #ou should a!!a(h an on1dis$iss lis!ener !o #our Dialo".

    Firs! de+ine !he Dialo"In!er+a(e.OnDis$issLis!enerin!er+a(e. This in!er+a(e hasHus! one $e!hod% onDis$iss)Dialo"In!er+a(e*% &hi(h &ill be (alled &hen !hedialo" is dis$issed. Then si$l# ass #our OnDis$issLis!ener i$le$en!a!ion !ose!OnDis$issLis!ener)*.

    >o&e'er% no!e !ha! dialo"s (an also be (an(elled. This is a se(ial (ase !ha!

    indi(a!es !he dialo" &as exli(i!l# (an(elled b# !he user. This &ill o((ur i+ !he userresses !he ba(, bu!!on !o (lose !he dialo"% or i+ !he dialo" exli(i!l# (alls(an(el)*)erhas +ro$ a 0an(el bu!!on in !he dialo"*. When a dialo" is(an(elled% !he OnDis$issLis!ener &ill s!ill be no!i+ied% bu! i+ #oud li,e !o bein+or$ed !ha! !he dialo" &as exli(i!l# (an(elled )and no! dis$issed nor$all#*%!hen #ou should re"is!er an Dialo"In!er+a(e.On0an(elLis!ener&i!hse!On0an(elLis!ener)*.

    DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4-

    64!12"86 #$%e ;9

    http://developer.android.com/reference/android/app/Activity.html#showDialog(int)http://developer.android.com/reference/android/app/Dialog.html#dismiss()http://developer.android.com/reference/android/app/Activity.html#dismissDialog(int)http://developer.android.com/reference/android/app/Dialog.html#dismiss()http://developer.android.com/reference/android/app/Activity.html#onCreateDialog(int)http://developer.android.com/reference/android/app/Activity.html#removeDialog(int)http://developer.android.com/reference/android/content/DialogInterface.OnDismissListener.htmlhttp://developer.android.com/reference/android/content/DialogInterface.OnDismissListener.html#onDismiss(android.content.DialogInterface)http://developer.android.com/reference/android/app/Dialog.html#setOnDismissListener(android.content.DialogInterface.OnDismissListener)http://developer.android.com/reference/android/app/Dialog.html#cancel()http://developer.android.com/reference/android/content/DialogInterface.OnCancelListener.htmlhttp://developer.android.com/reference/android/app/Dialog.html#setOnCancelListener(android.content.DialogInterface.OnCancelListener)http://developer.android.com/reference/android/app/Activity.html#showDialog(int)http://developer.android.com/reference/android/app/Dialog.html#dismiss()http://developer.android.com/reference/android/app/Activity.html#dismissDialog(int)http://developer.android.com/reference/android/app/Dialog.html#dismiss()http://developer.android.com/reference/android/app/Activity.html#onCreateDialog(int)http://developer.android.com/reference/android/app/Activity.html#removeDialog(int)http://developer.android.com/reference/android/content/DialogInterface.OnDismissListener.htmlhttp://developer.android.com/reference/android/content/DialogInterface.OnDismissListener.html#onDismiss(android.content.DialogInterface)http://developer.android.com/reference/android/app/Dialog.html#setOnDismissListener(android.content.DialogInterface.OnDismissListener)http://developer.android.com/reference/android/app/Dialog.html#cancel()http://developer.android.com/reference/android/content/DialogInterface.OnCancelListener.htmlhttp://developer.android.com/reference/android/app/Dialog.html#setOnCancelListener(android.content.DialogInterface.OnCancelListener)
  • 8/22/2019 Android Book.doc

    66/207

    DURGA SOFTWARE SOLUTIONSANDROID

    -reating an AlertDialog

    An Aler!Dialo"is an ex!ension o+ !he Dialo"(lass. I! is (aable o+ (ons!ru(!in"$os! dialo" user in!er+a(es and is !he su""es!ed dialo" !#e. ou should use i! +ordialo"s !ha! use an# o+ !he +ollo&in" +ea!uresK

    A !i!le A !ex! $essa"e One% !&o% or !hree bu!!ons A lis! o+ sele(!able i!e$s )&i!h o!ional (he(,boxes orradio