Introduction:
Android is an Linux Based Mobile Phone O era!in" S#s!e$% i! &as de'elo ed b# !he Goo"le and announ(ed as an o en sour(e )OR* Android is an o en sour(e so+!&are s!a(, &hi(h (o$es &i!h an o era!in" s#s!e$% $iddle&are (o$ onen!s% ,e# a li(a!ions li,e (alendar% address boo,% $essa"in" a li(a!ion and !he addi!ional API-s &hi(h $a,es $obile a li(a!ion de'elo $en! $ore +lexible and beau!i+ul.
Operating System: O era!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 /
End user en'iron$en!% hard&are s a(e (an be di++eren!. So$e bu"s $a# o((ur on In!el 0PU% Bu! no! SMF 0PUs. Need no! &orr# abou! !as, riori!ies OS &ill !a,e (are. A li(a!ion (rash is no! a ser'er issue.
No $iddle ar!# be!&een de'elo er and end1user. Users (an dire(!l# do&nload a li(a!ions +ro$ our &ebsi!es3D4Ds
5e# board and $ouse% lar"e s(reen si6e. Ma# or $a# no! ha'e a $i(% s ea,er% &eb (a$s7e!(. GPS s#s!e$ no! a'ailable e'en in la !o s.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 8
Android is an o en sour(e so+!&are s!a(, &hi(h (o$es &i!h an o era!in" s#s!e$% $iddle&are (o$ onen!s% ,e# a li(a!ions li,e (alendar% address boo,% $essa"in" a li(a!ion and !he addi!ional API-s &hi(h $a,es $obile a li(a!ion de'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 de lo#$en! +ees De'elo ers (o$$uni!# Versions /.9 1111111 : 0u (a,e /.; 1111111 : Donu! 8.<38./ 11111 : E(lair 8.8 1111111 : Fro#o 8.= 1111111 : Gin"erbread =.x 1111111 : >one#0o$bo ?.x 1111111 : I(e(rea$ Sand&i(h "latform Version A"I #evel Android $%& '$ Android =.8 /= Android =./ /8 Android =.< // Android 8.=.= /< Android 8.= @ Android 8.8 A Android 8./ B Android 8.<./ ; Android 8.< 9
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e =
? = 8 /
")one *ame otorola Mo!orola Miles!one CTB8< Mo!orola Miles!one Mo!orola Ba(,+li Mo!orola Duen(h CT= Mo!orola 0har$ Mo!orola Duen(h CT9 +,DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ?
DURGA SOFTWARE SOLUTIONS ANDROID >T0 Desire >T0 Le"end >T0 Ma"i( >T0 >ero >T0 Wild+ire >T0 Ta!!oo Samsung Sa$sun" Galax# S Sa$sun" Galax# S i(a Sa$sun" Galax# iB9<< Sa$sun" Galax# 9 Sa$sun" Galax# = Sa$sun" Galax# IA@@ Sony .ricsson Son# Eri(sson C eria C/< Son# Eri(sson C eria CA Son# Eri(sson C eria C/< Mini C eria C/< Mini Pro Dell Dell S!rea, Dell C0D=9 Dell C0D8A #/ LG O !i$us One LG O !i$us GT9?< LG GW;8< Acer A(er LiEuid A(er beTou(h E//< Videocon 4ideo(on Feus 4B9<< /armin Asus
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 9
DURGA SOFTWARE SOLUTIONS ANDROID Gar$in Asus A/< Spice S i(e MI=<< icroma0 Mi(ro$ax Andro A;<
1)y Android is success2 The ad'an!a"e o+ Android is #ou de'elo #our o&n hard&are and #ou &ill de'elo #our o&n a li(a!ions and release in!o $ar,e!. Android is o en sour(e% &here as o!hers are ro rie!ar# 'endors. S#$bian 111111111No,ia LG SEM0 Sa$sun" iOs 111111111111 iPhone Windo&s M1111 >T0 Sa$sun" Mo!orola >P Bla(,Berr#111111 Bla(,Berr# al$Os 1111 i aE Android 11111 >T0% LG% Mo!orola% Son#Erri(sun% Bell% 0is(o% A(er% > % Tablibs. -ompressed 3ormat Android .a , S#$bian .sis IPhone .a Bla(,Berr# .(od G8ME .Har Windo&s .(ab
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ;
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% Dis la#% 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* A li(a!ion Fra$e&or, +or desi"nin" a User In!er+a(e +ra$e&or, Libraries. Na!i'e A li(a!ions ) re ins!alled a li(a!ions*. li(a!ions
+ardware reference implementation:5 Android ro'ides a s e(i+i( hard&are re+eren(e i$ le$en!a!ion &hi(h ro'ides !he (a abili!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 a li(a!ion. I! a(!s as a (o$$uni(a!ion (hannel be!&een !he a li(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 B
Android a li(a!ion run in a se ara!e re o&n run!i$e en'iron$en! &hi(h is (alled Dalvi6 Virtual ac)ine 7DV 8% Application 3ramewor6:1 A li(a!ion +ra$e&or, ro'ides a &a# !o ex ose !he ser'i(es &hi(h !he o era!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% Tele hon# Mana"er% 4ie& s#s!e$ 7. E!(. 9ser Interface 3ramewor6:1 A UI +ra$e&or, allo&s !he a in a $ore "ra hi(al ri(h &a#.
#ibraries:A"I:1 I! &ill ro'ide basi( libraries and API-s &hi(h aids in !he de'elo $en! ro(ess o+ !he a li(a!ion. "re5Installed Applications:5 Android s!a(, (o$es &i!h !he se! o+ re1ins!alled a 0on!a(! boo, 7 e!(. li(a!ions li,e 0alendar%
Applications comes wit) Android ")one The na!i'e a li(a!ions &hi(h (o$e alon" side &i!h !he android o era!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!3a li(a!ions )G$ail a((oun! b# de+aul!*.
Android ar6et:1 I! is a (en!ral re osi!or# &here !housands o+ android a li(a!ions (an be do&nloaded a! +ree o+ (os!. ;rowser:1 The bro&ser runs on 1eb6it based 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" a li(a!ions and u!ili!ies are shi ed &i!h !he de'i(es. edia "layer:1 A Media Pla#er &ill be ro'ided b# de+aul! &hi(h su or!s 'arious audio3'ideo +or$a!s li,e .$ =% .$ ?% .&a' +iles. "icture Viewer:1 A de+aul! i(!ure 'ie&er a li(a!ion &ill (o$e &i!h su or!s di++eren! "ra hi(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 s e(ial!# !o s!ore (alendar and ersonal e1$ail a((oun!. /"S 7/lobal "ositioning System8 5 /oogle aps:5 Androoid ro'ides GPS ser'i(es +or a((essin" Goo"le Ma s. S S ased Applications:1 The de+aul! SMS a li(a!ions &ill allo& #ou !o send and re(ei'e $essa"es 3eatures
Application framewor6 enablin" reuse and re la(e$en! o+ (o$ onen!s Dalvi6 virtual mac)ine o !i$i6ed +or $obile de'i(es Integrated browser based on !he o en sour(e Web5i! en"ine Optimi<ed grap)ics o&ered b# a (us!o$ 8D "ra hi(s librar#J =D "ra hi(s based on !he O enGL ES /.< s e(i+i(a!ion )hard&are a((elera!ion o !ional* S=#ite +or s!ru(!ured da!a s!ora"e edia support +or (o$$on audio% 'ideo% and s!ill i$a"e +or$a!s )MPEG?% >.8;?% MP=% AA0% AMR% GPG% PNG% GIF* /S ,elep)ony )hard&are de enden!* ;luetoot)> .D/.> ?/> and 1i3i )hard&are de enden!* -amera> /"S> compass> and accelerometer )hard&are de enden!*
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e @
4ic) development environment in(ludin" a de'i(e e$ula!or% !ools +or debu""in"% $e$or# and er+or$an(e ro+ilin"% and a lu"in +or !he E(li se IDE
Android Arc)itecture The +ollo&in" dia"ra$ sho&s !he $aHor (o$ onen!s o+ !he Android o era!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 a li(a!ions in(ludin" an e$ail (lien!% SMS ro"ra$% (alendar% $a s% bro&ser% (on!a(!s% and o!hers. All a li(a!ions are &ri!!en usin" !he Ga'a ro"ra$$in" lan"ua"e.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /<
Application 3ramewor6 B# ro'idin" an o en de'elo $en! la!+or$% Android o++ers de'elo ers !he abili!# !o build ex!re$el# ri(h and inno'a!i'e a li(a!ions. De'elo ers 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(,"round ser'i(es% se! alar$s% add no!i+i(a!ions !o !he s!a!us bar% and $u(h% $u(h $ore. De'elo ers ha'e +ull a((ess !o !he sa$e +ra$e&or, APIs used b# !he (ore a li(a!ions. The a li(a!ion ar(hi!e(!ure is desi"ned !o si$ li+# !he reuse o+ (o$ onen!sJ an# a li(a!ion (an ublish i!s (a abili!ies and an# o!her a li(a!ion $a# !hen $a,e use o+ !hose (a abili!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 re la(ed b# !he user. Underl#in" all a
A ri(h and ex!ensible se! o+ 4ie&s !ha! (an be used !o build an a li(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 a li(a!ions !o a((ess da!a +ro$ o!her a li(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% "ra hi(s% and la#ou! +iles A No!i+i(a!ion Mana"er !ha! enables all a li(a!ions !o dis la# (us!o$ aler!s in !he s!a!us bar An A(!i'i!# Mana"er !ha! $ana"es !he li+e(#(le o+ a li(a!ions and ro'ides a (o$$on na'i"a!ion ba(, s!a(,
#ibraries Android in(ludes a se! o+ 030LL libraries used b# 'arious (o$ onen!s o+ !he Android s#s!e$. These (a abili!ies are ex osed !o de'elo ers !hrou"h !he Android a li(a!ion +ra$e&or,. So$e o+ !he (ore libraries are lis!ed belo&K
System - library 1 a BSD1deri'ed i$ le$en!a!ion o+ !he s!andard 0 s#s!e$ librar# )lib(*% !uned +or e$bedded Linux1based de'i(es edia #ibraries 1 based on Pa(,e!4ideoMs O en0OREJ !he libraries su or! la#ba(, and re(ordin" o+ $an# o ular audio and 'ideo +or$a!s% as &ell as s!a!i( i$a"e +iles% in(ludin" MPEG?% >.8;?% MP=% AA0% AMR% GPG% and PNG
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e //
Surface anager 1 $ana"es a((ess !o !he dis la# subs#s!e$ and sea$lessl# (o$ osi!es 8D and =D "ra hi( la#ers +ro$ $ul!i le a li(a!ions #ib1eb-ore 1 a $odern &eb bro&ser en"ine &hi(h o&ers bo!h !he Android bro&ser and an e$beddable &eb 'ie& S/# 1 !he underl#in" 8D "ra hi(s en"ine ?D libraries 1 an i$ le$en!a!ion based on O enGL ES /.< APIsJ !he libraries use ei!her hard&are =D a((elera!ion )&here a'ailable* or !he in(luded% hi"hl# o !i$i6ed =D so+!&are ras!eri6er 3ree,ype 1 bi!$a and 'e(!or +on! renderin" S=#ite 1 a o&er+ul and li"h!&ei"h! rela!ional da!abase en"ine a'ailable !o all a li(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 Ga'a ro"ra$$in" lan"ua"e. E'er# Android a li(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!i le 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 is re"is!er1based% and runs (lasses (o$ iled b# a Ga'a lan"ua"e (o$ iler !ha! ha'e been !rans+or$ed in!o !he .dex +or$a! b# !he in(luded NdxN !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+ !he so+!&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 a li(a!ion% android a li(a!ion has no (on!rol o'er !heir o&n li+e (#(le. Android a li(a!ion (o$ onen!s !ra(, !he s!a!e o+ !he a li(a!ion and !he# rea(! in a ro er $anner.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /8
Android $ana"ed resour(es in su(h a &a# !ha! !he a li(a!ion re$inds res onsi'e +or !he end users. The $ana"e$en! o+ !he resour(es is based on riori!i6a!ion ro(ess. Application priority1 The riori!# o+ !he hos!ed a li(a!ions de!er$ines !he ro(ess in &hi(h% !he ro(esses are ,illed and !he resour(es are !a,en ba(,. The riori!# o+ an a li(a!ion is eEual !o !he hi"hes! riori!# (o$ onen!. When !&o a li(a!ions are ha'in" !he sa$e riori!# !he ro(ess% !ha! &as s!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 a li(a!ion is de enden! on !he ser'i(e o++ered b# o!her a li(a!ion% !he o!her a li(a!ion &ill ha'e !he sa$e riori!# as !he +irs! a li(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" a li(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 a li(a!ion &i!h (o$ onen!s (urren!l# in!era(!in" &i!h !he user. This ro(ess &ill be runnin" 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 res onsible !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 /=
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 !he ro(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 a li(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 a li(a!ions. When !he# are re1laun(hed3re1s!ar!ed. These b# !he android run!i$e en'iron$en! &hene'er reEuired. #ife -ycle of an Activity 4isible li+e !i$e onS!ar!)* !o onS!o )*. Fore"round li+e !i$e onResu$e)* !o onPause)*. En!ire li+e !i$e on0rea!e)* !o onDes!ro#)*. An Activity comprises of ? states% /. Active or 4unning state:5 &hen !he a(!i'i!# is in !he +ore"round dis la# 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! be in!era(!in" &i!h !he a(!i'i!#. Ano!her A(!i'i!# &ill be resen! on !o o+ !his a(!i'i!#. A aused A(!i'i!# is (o$ le!el# ali'e !his is $ain!ains !he s!a!e a(!i'i!# and all 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 /?
=. Stopped State:5 An a(!i'i!# is said !o be in !he s!o ed 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 needed on o!her a(!i'i!ies or a li(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 !o on0rea!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# !he s#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!her a(!i'i!ies on !he s(reen and &ill be in!era(!in" &i!h !he end user.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /9
on-reate78K1 This $e!hod is (alled &hen !he a(!i'i!# is +irs! buil!. A! !his s!e all !he s!ar!u a(!i'i!ies are er+or$ed !ha! are reEuired b# !he a(!i'i!# in !he +or o!her s!e s.
onStart78 K1 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. on4esume78 K1 This $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"ause78 K1 This $e!hod is (alled b# !he a(!i'i!# &hen !he s#s!e$ is abou! !o s!ar! on o!her a(!i'i!#. This $e!hod is used !o (o$$i! un sa'ed (han"es% s!o all !he "ra hi(al user in!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. onStop78 K1
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /;
This $e!hod is (alled &hen !he a(!i'i!# is no lon"er 'isible !o !he end user. This o((urs be(a$e on o!her a(!i'i!# has been resu$ed or be(ause i! is bein" des!ro#ed. onDestroy78 K1 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. on4estart78 K1 This is (alled a+!er !he a(!i'i!# has been s!o a"ain. ed and be+ore i! is "e!!in" s!ar!ed
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 Su or!
Android SDK:1 The +unda$en!al blo(, o+ !he Android SD5 is !he Android API3Libraries !ha! ro'ide de'elo er !o a((ess !he Android so+!&are s!a(, &hi(h (on!ains di++eren! (o$ onen!s. Development ,ools:1 Android SD5 ro'ides di++eren! de'elo $en! !ools !o (on'er! !he &ri!!en a li(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'elo ed a li(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 /B
e$ula!ors run &i!h in !he D4M )Dal'i, 4ir!ual Ma(hine* $a,in" !he Android a li(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 a li(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 !he a(,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( a li(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 a li(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'elo er (o$$uni!# usin" &hi(h !he de'elo er (an build a li(a!ions in a less !i$e !a,in" !he hel o+ !he os!in"s3(on!a(!s on !he de'elo er (o$$uni!#. ,)e most important features w)ic) ma6es android differentiate from ot)er mobile application development platforms are: Goo"le Ma s 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 A li(a!ion Messa"in" /oogle aps and /.O coding:1 Goo"le Ma s 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 /A
Android ro'ides !he s e(ial!# !o in!e"ra!e Goo"le $a s &i!hin !he a li(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 a li(a!ion. The $a 'ie& &id"e! le! !he users3de'elo ers !o dis la# and $ani ula!e a Goo"le $a &i!hin !he a(!i'i!ies !o build $a based a li(a!ion Goo"le $a a li(a!ions (an be buildin" usin" !he /oogle ap in!er+a(e.
;ac6ground Services:1 Ba(,"round ser'i(es ro'ide a s e(ial!# !o (rea!e a li(a!ion !ha! i$ le$en!s an e'en! dri'en $odel &hi(h &or,s in !he ba(,"round &hile o!her a li(a!ions are runnin" (on!inuousl#. ExK 1 A s!o(, $ar,e! a li(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 de endin" 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! a $e(hanis$ o+ 0on!ex! Pro'ider. li(a!ions usin" !he
When an a li(a!ion (rea!es a da!abase i! is !o!all# res!ri(!ed +or use b# !ha! a li(a!ion i!sel+. The da!a (an be shared be!&een !&o di++eren! a shared er$issions b# usin" 0on!ex! Pro'ider. li(a!ions b# ro'idin"
Inter "rocess -ommunication:1 Messa"es (an be ex(han"ed be!&een !&o di++eren! a usin" In!en!s.
li(a!ion ro(essor
"eer5to5"eer -ommunication:1 Android o++ers eer1!o1 eer $essa"in" !ha! su or! ins!an! $essa"in"% resen! and in!er de'i(e3in!er a li(a!ion (o$$uni(a!ion.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /@
In!er A li(a!ion (o$$uni(a!ion enables !&o a ex(han"e $essa"es on behal+ o+ ea(h o!her. In!er de'i(e (o$$uni(a!ion enables !&o a de'i(es !o (o$$uni(a!e !o ea(h o!her.
li(a!ion ro(ess !o
All a li(a!ions in Android are eEual. Android does no! di++eren!ia!e be!&een na!i'e a li(a!ions and !hird ar!# a li(a!ions. There are !&o s(reens &hi(h (anno! be re la(ed b# !he de'elo er. /. User Lo(, S(reen 8. In1(all re rie'e S(reen Android SDK Installation and 9sage% Please +ollo& !he s!e s $en!ioned belo& !o ins!all Android SD5 and e(li se IDE !o "e! s!ar!ed &i!h a li(a!ion de'elo $en!. '% "reparing your development mac)ine Oour de'elo $en! s#s!e$ should +irs! do&nload so$e so+!&are be+ore #ou (an ro"ra$ +or i!. The +irs! one is !he GD5 &hi(h #ou (an do&nload +ro$ h!! K33&&&.ora(le.(o$3!e(hne!&or,3Ha'a3Ha'ase3do&nloads3index.h!$l
Oou (an use an# e(li se IDE abo'e =.? bu! #ou should al&a#s use !he la!es! 'ersion.
No!eK Ma,e sure #ou +irs! ins!all !he GD5 be+ore ins!allin" !he E(li se. /oogle 4ecommends Operating Systems Windo&s CP )=81bi!*% 4is!a )=81 or ;?1bi!*% or Windo&s B )=81 or ;?1bi!* Ma( OS C /<.9.A or la!er )xA; onl#* Linux )!es!ed on Linux Ubun!u >ard# >eron* ;?1bi! dis!ribu!ions $us! be (a able o+ runnin" =81bi! a Supported Development .nvironments .clipse ID. E(li se =.? )Gan#$ede* or =.9 )Galileo* -aution: There are ,no&n issues &i!h !he ADT lu"1in runnin" &i!h E(li se =.;. Please s!a# on =.9 un!il +ur!her no!i(e. E(li se ADT lu"in )in(luded in $os! E(li se IDE a(,a"es* I+ #ou need !o ins!all or u da!e E(li se% #ou (an do&nload i! +ro$ h!! K33&&&.e(li se.or"3do&nloads3.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 8/
li(a!ions.
Se'eral !# es o+ E(li se a(,a"es are a'ailable +or ea(h la!+or$. For de'elo in" Android a li(a!ions% &e re(o$$end !ha! #ou ins!all one o+ !hese a(,a"esK E(li se IDE +or Ga'a EE De'elo ers E(li se IDE +or Ga'a De'elo ers E(li se +or R0P3Plu"1in De'elo ers E(li se 0lassi( )'ersions =.9./ and hi"her* GD5 9 or GD5 ; )GRE 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 Ga'a )"(H* Ot)er development environments or ID.s GD5 9 or GD5 ; )GRE alone is no! su++i(ien!* A a(he An! /.;.9 or la!er +or Linux and Ma(% /.B or la!er +or Windo&s No! (o$ a!ible &i!h Gnu 0o$ iler +or Ga'a )"(H* No!eK I+ GD5 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 reEuire$en!s lis!ed abo'e. In ar!i(ular% no!e !ha! so$e Linux dis!ribu!ions $a# in(lude GD5 /.? or Gnu 0o$ iler +or Ga'a% bo!h o+ &hi(h are no! su or!ed +or Android de'elo $en!.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 88
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 8=
A+!er do&nloadin"% un a(, !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 un a(,ed SD5 dire(!or# on #our s#s!e$ P #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(! Pro er!ies. Under !he Ad'an(ed !ab% hi! !he En'iron$en! 4ariables bu!!on% and in !he dialo" !ha! (o$es u % double1(li(, on Pa!h )under S#s!e$ 4ariables*. Add !he +ull a!h !o !he !ools3 dire(!or# !o !he a!h.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 8?
8. In !he A'ailable So+!&are dialo"% (li(, Add.... =. In !he Add Si!e dialo" !ha! a ears% en!er a na$e +or !he re$o!e si!e )+or exa$ le% NAndroid Plu"inN* in !he NNa$eN +ield. In !he NLo(a!ionN +ield% en!er !his URLK h!! sK33dl1ssl."oo"le.(o$3android3e(li se3 I+ #ou ha'e !rouble a(Euirin" !he lu"in% #ou (an !r# usin" Nh!! N in !he URL% ins!ead o+ Nh!! sN )h!! s is re+erred +or se(uri!# reasons. 0li(, OK% ?. Ba(, in !he A'ailable So+!&are 'ie&% #ou should no& see NDe'elo er ToolsN added !o !he lis!. Sele(! !he (he(,box nex! !o De'elo er Tools% &hi(h &ill au!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 Android De'elo $en! Tools +ea!ures are lis!ed. 0li(, *e0t !o read and a((e ! !he li(ense a"ree$en! and ins!all an# de enden(ies% !hen (li(, 3inis). ;. Res!ar! E(li se.
?. 0li(, A l#% !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 .clipse:AD, I+ #ou are de'elo in" in E(li se and ha'e alread# ins!alled !he ADT Plu"in% +ollo& !hese s!e s !o a((ess !he Android SD5 and A4D Mana"er !oolK /. O en E(li se 8. 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 re osi!or#. ?. Sele(! !he (o$ onen!)s* #ouMd 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,:3 la!+or$s3 dire(!or# o+ #our SD5J ne& add1ons are sa'ed in !he Qsd,:3add1ons3 dire(!or#J sa$ les are sa'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 re la(ed*.
-onfiguration
In E(li se o en !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 +reEuen!l# )and +or e'er# &or,s a(e*. Sele(! no& 1indow 1: Android SDK and AVD anager +ro$ !he $enu.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 8;
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 8B
DURGA SOFTWARE SOLUTIONS ANDROID Press NIns!all sele(!edN and (on+ir$ !he li(ense +or all a(,a"e. A+!er !he ins!alla!ion res!ar! E(li se.
Device
Oou 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 NNe&N and $ain!ain !he +ollo&in".
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 8A
Press N0rea!e A4DN. This &ill (rea!e !he de'i(e. To !es! i+ #ou se!u is (orre(!% sele(! #our de'i(e and ress NS!ar!N.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 8@
-reating a +ello 1orld App for Android No& our s#s!e$ is read# +or &or,. S!ar! #our e(li se 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 =<
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. The lo&er end o+ i! sho&s !he (onsole and lo""er &hi(h is 'er# use+ul &hile debu""in".
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e =/
Steps to create +ello 1orld .0ample /. O en !he e(li se IDE in a &or, s a(e and (li(, File : Ne& : O!her : Android ProHe(! and (li(, Nex!
8. Fill !he de!ails &i!h roHe(! na$e as R>ello AndroidS. Under (on!en!s Sele(! R0rea!e ne& ProHe(! in Wor,s a(eS and !i(, RUse De+aul! Lo(a!ionS. 8. Sele(! build !ar"e! as !he la!es! SD5 a'ailable. Fill in !he ro er!ies as +ollo&s A li(a!ion Na$e I >ello Android Pa(,a"e Na$e I or".hello.>elloAndroid 0rea!e A(!i'i!# I >elloAndroid 0li(, RFinishS !o (rea!e !he roHe(! in #our &or,s a(e. =. Oou &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
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 A li(a!ion s!ar!s. Le! us loo, in!o !he +ile s!ru(!ure. The Mas!er +older is sa$e as A li(a!ion na$e i! is >ello Android in our (ase. I! (on!ains +our sub+olders in(ludin" sr(% "en% res and Android SD5 +iles. src I 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 R>elloAndroid.Ha'aS. a(,a"e or".hello.>elloAndroidJ i$ or! android.a .A(!i'i!#J i$ or! android.os.BundleJ ubli( (lass >elloAndroid ex!ends A(!i'i!# T 3UU 0alled &hen !he a(!i'i!# is +irs! (rea!ed. U3 VO'erride ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T su er.on0rea!e)sa'edIns!an(eS!a!e*J
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ==
se!0on!en!4ie&)R.la#ou!.$ain*J W W Le! us s end so$e !i$e unders!andin" !he (ode !ha! "o! au!o "enera!ed. I+ #ou ha'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 Ror".hello.>elloAndroidS. A a(,a"e is a na$es a(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 Android s e(i+i( Ha'a (ode. I$ or! is !he ,e# &ord &hi(h is used !o a((ess !he s!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 ha ens. The set-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(h is a sub(lass o+ an A(!i'i!#. The (lass +ur!her has a $e!hod (alled as on0rea!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 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 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 =?
res I I! is one o+ !he o!her i$ or!an! (on!en! +olders. I! (on!ains !hree sub+olders +or i$a"es na$el# dra&able Ihd i% dra&able Ild i% dra&able I $d i. 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 a li(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 a li(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 !he a li(a!ions. #et us loo6 into t)ese two important C # files in detail% main%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: QLinearLa#ou! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKorien!a!ionYN'er!i(alN androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN+illZ aren!N : QTex!4ie& androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidK!ex!YNVs!rin"3helloN 3: Q3LinearLa#ou!: I! s!ar!s &i!h !he LinearLa#ou! !a" &hi(h i$ lies !ha! &e &an! !o u! so$e (o$ onen!s on !he s(reen in a linear +ashion. There are $an# o!her la#ou!s also de+ined in Android &hi(h #ou &ill learn la!er. The orien!a!ion% &id!h and hei"h! des(ribe ho& !he la#ou! should loo,. We +ollo& i! &i!h a RTex!4ie&S (o$ onen! &hi(h is used !o dis la# !ex!s on !he s(reen. In !his exa$ le i! is !a,in" !he !ex! +ro$ !he RhelloS s!rin" de+ined in !he Rs!rin"s.x$lS. strings%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: Qresour(es: Qs!rin" na$eYNhelloN:>ello World% >elloAndroid[Q3s!rin": Qs!rin" na$eYNa Zna$eN:>ello AndroidQ3s!rin": Q3resour(es:
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e =9
Fro$ !he abo'e (on!en! #ou (an easil# $a,e ou! !ha! !he hello s!rin" (orres onds !o !he a(!ual s!rin" R>ello World% >elloAndroid[ This is sa$e as !he a li(a!ion na$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% Android anifest%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: Q$ani+es! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN a(,a"eYNor".hello.>elloAndroidN androidK'ersion0odeYN/N androidK'ersionNa$eYN/.<N: Qa li(a!ion androidKi(onYNVdra&able3i(onN androidKlabelYNVs!rin"3a Zna$eN: Qa(!i'i!# androidKna$eYN.+elloAndroidN androidKlabelYNVs!rin"3a Zna$eN: Qin!en!1+il!er: Qa(!ion androidKna$eYNandroid.in!en!.a(!ion.MAINN 3: Q(a!e"or# androidKna$eYNandroid.in!en!.(a!e"or#.LAUN0>ERN 3 : Q3in!en!1+il!er: Q3a(!i'i!#: Q3a li(a!ion: Q3$ani+es!: This +ile ou!lines !he $ain x$l and !he a(!i'i!# )!# e o+ ro(ess* &hi(h should s!ar! a+!er loadin" !he a li(a!ion. Oou (an de+ine s e(i+i( er$issions +or !he a li(a!ion li,e Ne!&or, a((ess and SMS inbox a((ess. The a(,a"e na$e% 'ersion nu$ber and o!her de!ails abou! !he a li(a!ion is also (on!ained in !his +ile. I! ri$aril# (onsis!s o+ +our i$ or!an! ar!s &hi(h (o$e !o"e!her as a CML +ile. These +our (o$ onen!s are Mani+es!% A li(a!ion% Per$ission and Ins!ru$en!a!ion.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e =;
Oou &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 !he SD5.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e =B
0li(, on !he RRun AsS as sho&n in !he +i"ure abo'e. A sele(!ion &indo& a as sho&n belo&. Sele(! !he Android A li(a!ion +ro$ i!.
ears
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 =A
0li(, on !he R$enuS ,e# on !he si$ula!or and #ou (an see !he resul! o+ !he a li(a!ion.
This exa$ le o+ ours &as 'er# basi( bu! i! s!ill is a (o$ le!e Android A li(a!ion and #ou (an !a,e so$e !i$e !o "ras !he s!ru(!ure and basi( as e(!s o+ an Android A li(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 =@
Application 3undamentals
/. A
li(a!ion 0o$ onen!s /. A(!i'a!in" (o$ onen!sK in!en!s 8. 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'ider 9. In!en! Android a li(a!ions are &ri!!en in !he Ga'a ro"ra$$in" lan"ua"e. The (o$ iled Ga'a (ode P alon" &i!h an# da!a and resour(e +iles reEuired b# !he a li(a!ion P is bundled b# !he aapt !ool in!o an Android package% an ar(hi'e +ile $ar,ed b# an .apk su++ix. This +ile is !he 'ehi(le +or dis!ribu!in" !he a li(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 a
B# de+aul!% e'er# a li(a!ion runs in i!s o&n Linux ro(ess. Android s!ar!s !he ro(ess &hen an# o+ !he a li(a!ionMs (ode needs !o be exe(u!ed% and shu!s do&n !he ro(ess &hen i!Ms no lon"er needed and s#s!e$ resour(es are reEuired b# o!her a li(a!ions. Ea(h ro(ess has i!s o&n 'ir!ual $a(hine )4M*% so a li(a!ion (ode runs in isola!ion +ro$ !he (ode o+ all o!her a li(a!ions. B# de+aul!% ea(h a li(a!ion is assi"ned a uniEue Linux user ID. Per$issions are se! so !ha! !he a li(a!ionMs +iles are 'isible onl# !o !ha! user and onl# !o !he a li(a!ion i!sel+ P al!hou"h !here are &a#s !o ex or! !he$ !o o!her a li(a!ions as &ell.
I!Ms ossible !o arran"e +or !&o a li(a!ions !o share !he sa$e user ID% in &hi(h (ase !he# &ill be able !o see ea(h o!herMs +iles. To (onser'e s#s!e$ resour(es% a li(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 ?<
Application -omponents A (en!ral +ea!ure o+ Android is !ha! one a li(a!ion (an $a,e use o+ ele$en!s o+ o!her a li(a!ions ) ro'ided !hose a li(a!ions er$i! i!*. For exa$ le% i+ #our a li(a!ion needs !o dis la# a s(rollin" lis! o+ i$a"es and ano!her a li(a!ion has de'elo ed a sui!able s(roller and $ade i! a'ailable !o o!hers% #ou (an (all u on !ha! s(roller !o do !he &or,% ra!her !han de'elo #our o&n. Oour a li(a!ion doesnM! in(or ora!e !he (ode o+ !he o!her a li(a!ion or lin, !o i!. Ra!her% i! si$ l# s!ar!s u !ha! ie(e o+ !he o!her a li(a!ion &hen !he need arises. For !his !o &or,% !he s#s!e$ $us! be able !o s!ar! an a li(a!ion ro(ess &hen an# ar! o+ i! is needed% and ins!an!ia!e !he Ga'a obHe(!s +or !ha! ar!. There+ore% unli,e a li(a!ions on $os! o!her s#s!e$s% Android a li(a!ions donM! ha'e a sin"le en!r# oin! +or e'er#!hin" in !he a li(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!e and run as needed. There are +our !# es o+ (o$ onen!sK
Activities An activity resen!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! dis la# ho!o"ra hs alon" &i!h !heir (a !ions. A !ex! $essa"in" a li(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'e user in!er+a(e% ea(h a(!i'i!# is inde enden! o+ !he o!hers. Ea(h one is i$ le$en!ed as a sub(lass o+ !he A(!i'i!# base (lass. An a li(a!ion $i"h! (onsis! o+ Hus! one a(!i'i!# or% li,e !he !ex! $essa"in" a li(a!ion Hus! $en!ioned% i! $a# (on!ain se'eral. Wha! !he a(!i'i!ies are% and ho& $an# !here are de ends% o+ (ourse% on !he a li(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 a li(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 ?/
!o o+ o!her &indo&s. An a(!i'i!# (an also $a,e use o+ addi!ional &indo&s P +or exa$ le% a o 1u dialo" !ha! (alls +or a user res onse 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 P obHe(!s deri'ed +ro$ !he base 4ie& (lass. Ea(h 'ie& (on!rols a ar!i(ular re(!an"ular s a(e &i!hin !he &indo&. Paren! 'ie&s (on!ain and or"ani6e !he la#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 res ond !o user a(!ions dire(!ed a! !ha! s a(e. Thus% 'ie&s are &here !he a(!i'i!#Ms in!era(!ion &i!h !he user !a,es la(e. For exa$ le% a 'ie& $i"h! dis la# a s$all i$a"e and ini!ia!e an a(!ion &hen !he user !a s !ha! i$a"e. Android has a nu$ber o+ read#1$ade 'ie&s !ha! #ou (an use P in(ludin" bu!!ons% !ex! +ields% s(roll bars% $enu i!e$s% (he(, boxes% and $ore. A 'ie& hierar(h# is la(ed &i!hin an a(!i'i!#Ms &indo& b# !he A(!i'i!#.se!0on!en!4ie&)* $e!hod. The content view is !he 4ie& obHe(! a! !he roo! o+ !he hierar(h#. Services A service doesnM! ha'e a 'isual user in!er+a(e% bu! ra!her runs in !he ba(,"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!(h da!a o'er !he ne!&or, or (al(ula!e so$e!hin" and ro'ide !he resul! !o a(!i'i!ies !ha! need i!. Ea(h ser'i(e ex!ends !he Ser'i(e base (lass. A ri$e exa$ le is a $edia la#er la#in" son"s +ro$ a la# lis!. The la#er a li(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 &ill ex e(! !he $usi( !o ,ee la#in" e'en a+!er !he# lea'e !he la#er and be"in so$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!Ms ossible !o (onne(! !o )bind !o* an on"oin" ser'i(e )and s!ar! !he ser'i(e i+ i!Ms 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 ex oses. For !he $usi(
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ?8
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 a li(a!ion ro(ess. So !ha! !he# &onM! blo(, o!her (o$ onen!s or !he user in!er+a(e% !he# o+!en s a&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 ?=
QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: QLinearLa#ou! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKorien!a!ionYN'er!i(alN androidKla#ou!Z&id!hYN$a!(hZ aren!N androidKla#ou!Zhei"h!YN$a!(hZ aren!N androidK"ra'i!#YN(en!erN: QTex!4ie& androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidK!ex!YNSer'i(es De$oN androidK addin"YN8<d N3: QBu!!on androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidKidYNVLid3bu!!onS!ar!N androidK!ex!YNS!ar!N: Q3Bu!!on: QBu!!on androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidK!ex!YNS!o N androidKidYNVLid3bu!!onS!o N: Q3Bu!!on: Q3LinearLa#ou!: ServiceActivity%java a(,a"e (o$.ser'i(eJ i$ i$ i$ i$ i$ i$ i$ or! android.a .A(!i'i!#J or! android.(on!en!.In!en!J or! android.os.BundleJ or! android.u!il.Lo"J or! android.'ie&.4ie&J or! android.'ie&.4ie&.On0li(,Lis!enerJ or! android.&id"e!.Bu!!onJ
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ??
ubli( (lass Ser'i(eA(!i'i!# ex!ends A(!i'i!# i$ le$en!s On0li(,Lis!ener T ri'a!e s!a!i( +inal S!rin" TAG Y NSer'i(esDe$oNJ Bu!!on bu!!onS!ar!% bu!!onS!o J VO'erride ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T su er.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 W ubli( 'oid on0li(,)4ie& sr(* T s&i!(h )sr(."e!Id)** T (ase R.id.bu!!onS!ar!K Lo".d)TAG% Non0li(,K s!ar!in" ser'i(eN*J s!ar!Ser'i(e)ne& In!en!)!his% M#Ser'i(e.(lass**J brea,J (ase R.id.bu!!onS!o K Lo".d)TAG% Non0li(,K s!o in" ser'i(eN*J s!o Ser'i(e)ne& In!en!)!his% M#Ser'i(e.(lass**J brea,J W W W yService%java a(,a"e (o$.ser'i(eJ i$ i$ i$ i$ or! android.a .Ser'i(eJ or! android.(on!en!.In!en!J or! android.$edia.MediaPla#erJ or! android.os.IBinderJ
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ?9
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 T MediaPla#er la#erJ VO'erride ubli( IBinder onBind)In!en! in!en!* T re!urn nullJ W VO'erride ubli( 'oid on0rea!e)* T Toas!.$a,eTex!)!his% NM# Ser'i(e 0rea!edN% Toas!.LENGT>ZLONG*.sho&)*J la#er Y MediaPla#er.(rea!e)!his% R.ra&.robo!ro(,*J la#er.se!Loo in")+alse*J 33 Se! loo in" W VO'erride ubli( 'oid onDes!ro#)* T Toas!.$a,eTex!)!his% NM# Ser'i(e S!o edN% Toas!.LENGT>ZLONG*.sho&)*J la#er.s!o )*J W VO'erride ubli( 'oid onS!ar!)In!en! in!en!% in! s!ar!id* T Toas!.$a,eTex!)!his% NM# Ser'i(e S!ar!edN% Toas!.LENGT>ZLONG*.sho&)*J la#er.s!ar!)*J W W Android anifest%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: Q$ani+es! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN a(,a"eYN(o$.ser'i(eN
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ?;
androidK'ersion0odeYN/N androidK'ersionNa$eYN/.<N: Qa li(a!ion androidKi(onYNVdra&able3i(onN androidKlabelYNVs!rin"3a Zna$eN: Qa(!i'i!# androidKna$eYN.Ser'i(eA(!i'i!#N androidKlabelYNVs!rin"3a Zna$eN: Qin!en!1+il!er: Qa(!ion androidKna$eYNandroid.in!en!.a(!ion.MAINN 3: Q(a!e"or# androidKna$eYNandroid.in!en!.(a!e"or#.LAUN0>ERN 3: Q3in!en!1+il!er: Q3a(!i'i!#: Qser'i(e androidKenabledYN!rueN androidKna$eYN.M#Ser'i(eN 3: Q3a li(a!ion: Quses1sd, androidK$inSd,4ersionYNAN 3: Q3$ani+es!: ;roadcast receivers A broadcast receiver is a (o$ onen! !ha! does no!hin" bu! re(ei'es and rea(!s !o broad(as! announ(e$en!s. Man# broad(as!s ori"ina!e in s#s!e$ (ode P +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 a lan"ua"e re+eren(e. A li(a!ions (an also ini!ia!e broad(as!s P +or exa$ le% !o le! o!her a li(a!ions ,no& !ha! so$e da!a has been do&nloaded !o !he de'i(e and is a'ailable +or !he$ !o use. An a li(a!ion (an ha'e an# nu$ber o+ broad(as! re(ei'ers !o res ond !o an# announ(e$en!s i! (onsiders i$ or!an!. All re(ei'ers ex!end !he Broad(as!Re(ei'er base (lass. Broad(as! re(ei'ers do no! dis la# a user in!er+a(e. >o&e'er% !he# $a# s!ar! an a(!i'i!# in res onse !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 userMs a!!en!ion in 'arious &a#s P +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 !he s!a!us bar% &hi(h users (an o en !o "e! !he $essa"e. ;roadcast.0ample:5
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ?B
AlarmActivity%java a(,a"e (o$.broad(as!J i$ i$ i$ i$ i$ i$ i$ i$ or! android.a .A(!i'i!#J or! android.a .Alar$Mana"erJ or! android.a .Pendin"In!en!J or! android.(on!en!.In!en!J or! android.os.BundleJ or! android.'ie&.4ie&J or! android.&id"e!.Edi!Tex!J or! android.&id"e!.Toas!J
ubli( (lass Alar$A(!i'i!# ex!ends A(!i'i!# T VO'erride ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ?A
su er.on0rea!e)sa'edIns!an(eS!a!e*J se!0on!en!4ie&)R.la#ou!.$ain*J W ubli( 'oid s!ar!Aler!)4ie& 'ie&* T 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!A li(a!ion0on!ex!)*% <% in!en!% <*J Alar$Mana"er alar$Mana"er Y )Alar$Mana"er* "e!S#s!e$Ser'i(e)ALARMZSER4I0E*J alar$Mana"er.se!)Alar$Mana"er.RT0ZWA5EUP% S#s!e$.(urren!Ti$eMillis)*L )i U /<<<*% endin"In!en!*J Toas!.$a,eTex!)!his% NAlar$ se! in N L i L N se(ondsN% Toas!.LENGT>ZLONG*.sho&)*J W W
y;roadcast4eceiver%java a(,a"e (o$.broad(as!J i$ i$ i$ i$ i$ or! android.(on!en!.Broad(as!Re(ei'erJ or! android.(on!en!.0on!ex!J or! android.(on!en!.In!en!J or! android.os.4ibra!orJ or! android.&id"e!.Toas!J
ubli( (lass M#Broad(as!Re(ei'er ex!ends Broad(as!Re(ei'er T VO'erride ubli( 'oid onRe(ei'e)0on!ex! (on!ex!% In!en! in!en!* T Toas!.$a,eTex!)(on!ex!% NPlease &a,e u #our !i$e is O'er[[[[.N%
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ?@
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<<<*J W W main%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: QLinearLa#ou! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKorien!a!ionYN'er!i(alN androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN+illZ aren!N: QEdi!Tex! androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidKidYNVLid3!i$eN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKhin!YNNu$ber o+ se(ondsN androidKin u!T# eYNnu$berDe(i$alN3: QBu!!on androidK!ex!YNS!ar! 0oun!erN androidKon0li(,YNs!ar!Aler!N androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N3: Q3LinearLa#ou!: Android anifest%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: Q$ani+es! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN a(,a"eYN(o$.broad(as!N androidK'ersion0odeYN/N androidK'ersionNa$eYN/.<N: Quses1sd, androidK$inSd,4ersionYNAN 3:
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 9<
Qa li(a!ion androidKi(onYNVdra&able3i(onN androidKlabelYNVs!rin"3a Zna$eN: Qa(!i'i!# androidKna$eYN.Alar$A(!i'i!#N androidKlabelYNVs!rin"3a Zna$eN: Qin!en!1+il!er: Qa(!ion androidKna$eYNandroid.in!en!.a(!ion.MAINN 3: Q(a!e"or# androidKna$eYNandroid.in!en!.(a!e"or#.LAUN0>ERN 3: Q3in!en!1+il!er: Q3a(!i'i!#: Qre(ei'er androidKna$eYNM#Broad(as!Re(ei'erN3: Q3a li(a!ion: Quses1 er$ission androidKna$eYNandroid. er$ission.4IBRATEN3: Q3$ani+es!:
-ontent providers A content provider $a,es a s e(i+i( se! o+ !he a li(a!ionMs da!a a'ailable !o o!her a li(a!ions. The da!a (an be s!ored in !he +ile s#s!e$% in an SDLi!e da!abase% or in an# o!her $anner !ha! $a,es sense. The (on!en! ro'ider ex!ends !he 0on!en!Pro'ider base (lass !o i$ le$en! a s!andard se! o+ $e!hods !ha! enable o!her a li(a!ions !o re!rie'e and s!ore da!a o+ !he !# e i! (on!rols. >o&e'er% a li(a!ions do no! (all !hese $e!hods dire(!l#. Ra!her !he# use a 0on!en!Resol'er obHe(! and (all i!s $e!hods ins!ead. A 0on!en!Resol'er (an !al, !o an# (on!en! ro'iderJ i! (oo era!es &i!h !he ro'ider !o $ana"e an# in!er ro(ess (o$$uni(a!ion !ha!Ms in'ol'ed. Whene'er !hereMs a reEues! !ha! should be handled b# a ar!i(ular (o$ onen!% Android $a,es sure !ha! !he a li(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/
s!ar!in" i! i+ ne(essar#% and !ha! an a ro ria!e ins!an(e o+ !he (o$ onen! is a'ailable% (rea!in" !he ins!an(e i+ ne(essar#. Activating components: intents 0on!en! ro'iders are a(!i'a!ed &hen !he#Mre !ar"e!ed b# a reEues! +ro$ a 0on!en!Resol'er. The o!her !hree (o$ onen!s P a(!i'i!ies% ser'i(es% and broad(as! re(ei'ers P are a(!i'a!ed b# as#n(hronous $essa"es (alled intents. An in!en! is an In!en! obHe(! !ha! holds !he (on!en! o+ !he $essa"e. For a(!i'i!ies and ser'i(es% i! na$es !he a(!ion bein" reEues!ed and s e(i+ies !he URI o+ !he da!a !o a(! on% a$on" o!her !hin"s. For exa$ le% i! $i"h! (on'e# a reEues! +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 se ara!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!)*. The res ondin" 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!#Ms onNe&In!en!)* $e!hod !o ass i! an# subseEuen! in!en!s. One a(!i'i!# o+!en s!ar!s !he nex! one. I+ i! ex e(!s a resul! ba(, +ro$ !he a(!i'i!# i!Ms 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! ex e(! !o be re!urned !he (hosen ho!o. The resul! is re!urned in an In!en! obHe(! !ha!Ms assed !o !he (allin" a(!i'i!#Ms onA(!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(eMs onS!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 an on"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 is no! 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
user in!er+a(e* +or (on!rollin" !he la#ba(,. The a(!i'i!# &ould (all bindService() !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 a li(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. Android deli'ers !he in!en! !o all in!eres!ed broad(as! re(ei'ers b# (allin" !heir onRe(ei'e)* $e!hods.
S)utting down components A (on!en! ro'ider is a(!i'e onl# &hile i!Ms res ondin" !o a reEues! +ro$ a 0on!en!Resol'er. And a broad(as! re(ei'er is a(!i'e onl# &hile i!Ms res ondin" !o a broad(as! $essa"e. So !hereMs no need !o ex li(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#Mre 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!h startActivityForResult()* b# (allin" +inishA(!i'i!#)*. A ser'i(e (an be s!o ed b# (allin" i!s s!o Sel+)* $e!hod% or b# (allin" 0on!ex!.s!o Ser'i(e)*.
,)e manifest file Be+ore Android (an s!ar! an a li(a!ion (o$ onen!% i! $us! learn !ha! !he (o$ onen! exis!s. There+ore% a li(a!ions de(lare !heir (o$ onen!s in a $ani+es! +ile !ha!Ms bundled in!o !he Android a(,a"e% !he .apk +ile !ha! also holds !he a li(a!ionMs (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 a li(a!ions. I! does a nu$ber o+ !hin"s in addi!ion !o de(larin" !he a li(a!ionMs (o$ onen!s% su(h as na$in" an# libraries !he a li(a!ion needs !o be lin,ed a"ains! )besides !he de+aul! Android librar#* and iden!i+#in" an# er$issions !he a li(a!ion ex e(!s !o be "ran!ed.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 9=
Bu! !he rin(i al !as, o+ !he $ani+es! is !o in+or$ Android abou! !he a (o$ onen!s. For exa$ le% an a(!i'i!# $i"h! be de(lared as +ollo&sK QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: Q$ani+es! . . . : Qa li(a!ion . . . : Qa(!i'i!# androidKna$eYN(o$.exa$ le. roHe(!.Frene!i(A(!i'i!#N androidKi(onYNVdra&able3s$allZ i(. n"N androidKlabelYNVs!rin"3+rene!i(LabelN ... : Q3a(!i'i!#: ... Q3a li(a!ion: Q3$ani+es!:
li(a!ionMs
The name a!!ribu!e o+ !he Qa(!i'i!#: ele$en! na$es !he A(!i'i!# sub(lass !ha! i$ le$en!s !he a(!i'i!#. The icon and label a!!ribu!es oin! !o resour(e +iles (on!ainin" an i(on and label !ha! (an be dis la#ed !o users !o re resen! !he a(!i'i!#. The o!her (o$ onen!s are de(lared in a si$ilar &a# P Qser'i(e: ele$en!s +or ser'i(es% Qre(ei'er: ele$en!s +or broad(as! re(ei'ers% and Q ro'ider: ele$en!s +or (on!en! ro'iders. A(!i'i!ies% ser'i(es% and (on!en! ro'iders !ha! are no! de(lared in !he $ani+es! are no! 'isible !o !he s#s!e$ and are (onseEuen!l# ne'er run. >o&e'er% broad(as! re(ei'ers (an ei!her be de(lared in !he $ani+es!% or !he# (an be (rea!ed d#na$i(all# in (ode )as Broad(as!Re(ei'er obHe(!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 a li(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. /. Ex li(i! In!en!s
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 9?
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!*J ExK1 on0li(,)4ie& '*T In!en! $#In!en!Yne& In!en!)"e!A li(a!ion0on!ex!)*3Firs!A(!i'i!#.!his% Se(ondA(!i'i!#.(lass*J W Implicit Intents:5 In!en! $#In!en!Yne& In!en!)a(!ion% URI% RDa!aS*J ExK1 In!en! $#In!en!Yne& In!en!)In!en!.A0TIONZDIAL*J s!ar!A(!i'i!#)$#In!en!*J Trans+errin" da!a b# usin" .0tra;undle (lass I+ #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!# T 33Oour $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* T 33Oour (ode here W W 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
Qa(!i'i!# androidKna$eYN.Nex!A(!i'i!#N androidKlabelYNVs!rin"3a Zna$eN: Q3a(!i'i!#: No!e !ha! here &e ha'e no! used in!en! +il!er% sin(e &e are "oin" !o use an ex li(i! in!en!% !he s#n!ax o+ in!en! +il!er is Qin!en!1+il!er: Qa(!ion androidKna$eYNQa(!ion here:N3: Q(a!e"or# androidKna$eYNQ(a!e"or# here:N3: Q3in!en!1+il!er: >ere% action P The "eneral a(!ion !o be er+or$ed category P Gi'es addi!ional in+or$a!ion abou! !he a(!ion !o exe(u!e. For exa$ le% 0ATEGOROZLAUN0>ER $eans i! should a !o 1le'el a ear in !he Laun(her as a li(a!ion% &hile 0ATEGOROZALTERNATI4E $eans i! should be
in(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 a li(a!ion !ab belo& !he DAndroid anifest%0mlE +ile% and
in DApplication *odesE se(!ion (li(, DAddE bu!!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;
>ere% #ou ha'e !o (rea!e and in!en! &i!h -urrentActivity%t)is as +irs! ara$e!er and !he !he ne0t activity as 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 Actions:Activity actions /. A0TIONZMAIN K1 I! de+ines !he $ain en!r# oin! o+ !he a(!i'i!#.)Gus! li,e a $ain)* $e!hod*. ExK1android.in!en!.a(!ion.MAIN )!he 'alue o+ !he a!!ribu!e*. 8. A0TIONZ4IEW K1 I! dis la#s !he da!a !o !he user. android.in!en!.a(!ion.4IEW =. A0TIONZEDIT K1 I! ro'ides ex li(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(!ed i!e$. ExK 0on!a(! Boo,111: i(,111:0ALL3DIAL 9. A0TIONZDIAL K1 I! de+ined a nu$ber &hi(h is s e(i+ied b# !he da!a. I! dis la#s a user in!er+a(e &i!h !he nu$ber !o be dialed allo&in" !he user !o ex li(i!l# s!ar! !he (all. ;. A0TIONZ0ALL K1 I! ini!ia!e a dire(! (all !o !he nu$ber s e(i+ied. B. A0TIONZANSWER K1i! handles an in(o$in" hone (all. A. A0TIONZSEAR0> K1 I! er+or$s a sear(h o era!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. /<.A0TIONZSON0 K1i! er+or$s da!a s#n(hroni6a!ion &i!h !he o!her a(!i'i!#. Standard -ategories /. 0ATEGOROZLAUN0>ERK1The A(!i'i!# de+ines &i!h !his (a!e"or# should be dis la#ed in !he !o le'el laun(her. 8. 0ATEGOROZDEFAULTK1This (a!e"or# de+ines i+ !he a(!i'i!# should be an o !ion +or !he de+aul! a(!ion.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 9B
=. 0ATEGOROZ0ARZDO05K1I! de+ines an a(!i'i!# !o run &hen a de'i(e is inser!ed in a (ar do(,. For (ars. ?. 0ATEGOROZ0ARZMODEK1I! is used !o indi(a!es !ha! !he a(!ion (an be used in a (ar en'iron$en!. 9. 0ATEGOROZTABK1I! is su osed !o be used as a !ab inside a TabA(!i'i!#) rede+ined (lass*. ;. 0ATEGOROZINFOK1 I! ro'ides !he In+or$a!ion abou! !he a(,a"e i! is la(ed in!o i!. Standard ;roadcast Actions /. A0TIONZBATEROZ0>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. A0TIONZBATEROZLOW K1 I! indi(a!es lo& ba!!er# (ondi!ions on !he de'i(e. ExK1 I! is a Dialo" box. =. A0TIONZBATEROZO5K1 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 a Toas! $essa"e.
+ow to create a new Android activity The Android de'elo $en! aradi"$ in!rodu(es +or !he de'elo er !he RA(!i'i!#SK Q: Durin" de'elo $en! #ou &ill +ind i! eas# !o &ra 1u ar!s o+ !he +un(!ionali!# o+ #our (ode in!o inde enden! a(!i'i!ies% &i!h !heir o&n li+e (#(le. More abou! a(!i'i!# li+e (#(le on !he Android de'elo ers &ebsi!e.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 9A
.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*J in!en!.se!0lassNa$e)!his% Se(ondar#A(!i'i!#.(lass."e!Na$e)**J s!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!. Oou &ill a(hie'e !his usin" !he Bundle (lass% !o en(a sula!e #our da!a. Exa$ leK In!en! in!en! Y ne& In!en!)*J Bundle bun Y ne& Bundle)*J bun. u!S!rin")S ara$Zs!rin"S% R!he a(!ual s!rin"S*J 33 add !&o ara$e!ersK a s!rin" and a boolean bun. u!Boolean)S ara$ZboolS% !rue*J in!en!.se!0lass)!his% Se(ondar#A(!i'i!#.(lass*J in!en!. u!Ex!ras)bun*J s!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)*J S!rin" ara$/ Y bun."e!S!rin")S ara$Zs!rin"S*J boolean ara$8 Y bun."e!Boolean)S ara$ZboolS*J
Some useful default activities: Par! o+ !he beau!# o+ Android is !ha! #ou (an en(a sula!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@
In!en! in!en! Y ne& In!en!)In!en!.A0TIONZSENDTO% Uri. arse)S$ail!oKo++i(eVexa$ le.(o$S**J in!en!. u!Ex!ra)SsubHe(!S% R$# subHe(!S*J in!en!. u!Ex!ra)Sbod#S% R$# $essa"eS*J s!ar!A(!i'i!#)in!en!*J 8. Bro&se !o a &eb1 a"e In!en! in!en! Y ne& In!en!)In!en!.A0TIONZ4IEW% Uri. arse)Sh!! K33&&&."oo"le.(o$S**J s!ar!A(!i'i!#)in!en!*J =. Wri!e a SMS In!en! in!en! Y ne& In!en!)In!en!.A0TIONZSENDTO% Uri. arse)Ss$sK33S**J in!en!. u!Ex!ra)SaddressS% RS*J in!en!. u!Ex!ra)Ss$sZbod#S% R$# $essa"eS*J s!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> *J in!en!. u!Ex!ra)Sear(hMana"er.DUERO% Rsear(h !his !ex!S*J s!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)Sh!! K33en.&i,!ionar#.or"3&i,i3S L R&ordS**J s!ar!A(!i'i!#)in!en!*J ;. Ge! !he Wi,i edia a"e o+ so$e &ords S!rin" uri Y Rh!! K33en.&i,i edia.or"3&i,i3S L R$# !ex!SJ In!en! in!en! Y ne& In!en!)In!en!.A0TIONZ4IEW% Uri. arse)uri**J s!ar!A(!i'i!#)in!en!*J Intent filters An In!en! obHe(! (an ex li(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 ;<
i!. Bu! i+ a !ar"e! is no! ex li(i!l# na$ed% Android $us! lo(a!e !he bes! (o$ onen! !o res ond !o !he in!en!. I! does so b# (o$ arin" !he In!en! obHe(! !o !he intent filters o+ o!en!ial !ar"e!s. A (o$ onen!Ms 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#Mre de(lared in !he $ani+es! +ile. >ereMs an ex!ension o+ !he re'ious exa$ le !ha! adds !&o in!en! +il!ers !o !he a(!i'i!#K QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: Q$ani+es! . . . : Qa li(a!ion . . . : Qa(!i'i!# androidKna$eYN(o$.exa$ le. roHe(!.Frene!i(A(!i'i!#N androidKi(onYNVdra&able3s$allZ i(. n"N androidKlabelYNVs!rin"3+rene!i(LabelN ... : Qin!en!1+il!er . . . : Qa(!ion androidKna$eYNandroid.in!en!.a(!ion.MAINN 3: Q(a!e"or# androidKna$eYNandroid.in!en!.(a!e"or#.LAUN0>ERN 3: Q3in!en!1+il!er: Qin!en!1+il!er . . . : Qa(!ion androidKna$eYN(o$.exa$ le. roHe(!.BOUN0EN 3: Qda!a androidK$i$eT# eYNi$a"e3H e"N 3: Q(a!e"or# androidKna$eYNandroid.in!en!.(a!e"or#.DEFAULTN 3: Q3in!en!1+il!er: Q3a(!i'i!#: ... Q3a li(a!ion: Q3$ani+es!: The +irs! +il!er in !he exa$ le P !he (o$bina!ion o+ !he a(!ion Nandroid.intent.action.MAINN and !he (a!e"or# Nandroid.intent.category.LA N!"#RN P is a (o$$on one. I! $ar,s !he a(!i'i!# as one !ha! should be re resen!ed in !he a li(a!ion laun(her% !he s(reen lis!in" a li(a!ions users (an laun(h on !he de'i(e. In o!her &ords% !he a(!i'i!# is !he en!r# oin! +or !he a li(a!ion% !he ini!ial one users &ould see &hen !he# (hoose !he a li(a!ion in !he laun(her. The se(ond +il!er de(lares an a(!ion !ha! !he a(!i'i!# (an er+or$ on a ar!i(ular !# e o+ da!a.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ;/
A (o$ onen! (an ha'e an# nu$ber o+ in!en! +il!ers% ea(h one de(larin" a di++eren! se! o+ (a abili!ies. I+ i! doesnM! ha'e an# +il!ers% i! (an be a(!i'a!ed onl# b# in!en!s !ha! ex li(i!l# na$e !he (o$ onen! as !he !ar"e!. For a broad(as! re(ei'er !ha!Ms (rea!ed and re"is!ered in (ode% !he in!en! +il!er is ins!an!ia!ed dire(!l# as an In!en!Fil!er obHe(!. 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
A dialo" is a s$all &indo& !ha! a ears in +ron! o+ !he (urren! A(!i'i!#. The underl#in" A(!i'i!# loses +o(us and !he dialo" a((e !s all user in!era(!ion. Dialo"s are nor$all# used +or no!i+i(a!ions and shor! a(!i'i!ies !ha! dire(!l# rela!e !o !he a li(a!ion in ro"ress. The Android API su or!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. The Aler!Dialo" is (a able o+ (ons!ru(!in" $os! dialo" user in!er+a(es and is !he su""es!ed dialo" !# e. Pro"ressDialo" A dialo" !ha! dis la#s a ro"ress &heel or ro"ress bar. Be(ause i!Ms an ex!ension o+ !he Aler!Dialo"% i! also su or!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 dis la#ed as a ar! o+ an A(!i'i!#. Oou should nor$all# (rea!e dialo"s +ro$ &i!hin #our A(!i'i!#Ms 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! !he No&nerN o+ ea(h dialo". As su(h% ea(h dialo" inheri!s (er!ain ro er!ies +ro$ !he A(!i'i!#. For exa$ le% &hen a dialo" is o en% !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!#. Oou (an% ho&e'er% a!!a(h i! !o an A(!i'i!# &i!h se!O&nerA(!i'i!#)A(!i'i!#*.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ;=
When #ou &an! !o sho& a dialo"% (all sho&Dialo")in!* and ass i! an in!e"er !ha! uniEuel# iden!i+ies !he dialo" !ha! #ou &an! !o dis la#. When a dialo" is reEues!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 dis la#ed% Android also (alls !he o !ional (allba(, $e!hod onPre areDialo")in!% Dialo"*. De+ine !his $e!hod i+ #ou &an! !o (han"e an# ro er!ies o+ !he dialo" ea(h !i$e i! is o ened. This $e!hod is (alled e'er# !i$e a dialo" is o ened% &hereas on0rea!eDialo")in!* is onl# (alled !he 'er# +irs! !i$e a dialo" is o ened. I+ #ou donM! de+ine onPre areDialo")*% !hen !he dialo" &ill re$ain !he sa$e as i! &as !he re'ious !i$e i! &as o ened. This $e!hod is also assed !he dialo"Ms ID% alon" &i!h !he Dialo" obHe(! #ou (rea!ed in on0rea!eDialo")*. The bes! &a# !o de+ine !he on0rea!eDialo")in!* and onPre areDialo")in!% Dialo"* (allba(, $e!hods is &i!h a switch s!a!e$en! !ha! (he(,s !he id ara$e!er !ha!Ms assed in!o !he $e!hod. Ea(h case should (he(, +or a uniEue dialo" ID and !hen (rea!e and de+ine !he res e(!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 !o indi(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 <J s!a!i( +inal in! DIALOGZGAMEO4ERZID Y /J Then% de+ine !he on0rea!eDialo")in!* (allba(, &i!h a s&i!(h (ase +or ea(h IDK ro!e(!ed Dialo" on0rea!eDialo")in! id* T Dialo" dialo"J s&i!(h)id* T (ase DIALOGZPAUSEDZIDK 33 do !he &or, !o de+ine !he ause Dialo" brea,J (ase DIALOGZGAMEO4ERZIDK 33 do !he &or, !o de+ine !he "a$e o'er Dialo" brea,J de+aul!K dialo" Y nullJ
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ;?
W re!urn dialo"J W When i!Ms !i$e !o sho& one o+ !he dialo"s% (all sho&Dialo")in!* &i!h !he ID o+ a dialo"K sho&Dialo")DIALOGZPAUSEDZID*J Dismissing a Dialog When #ouMre 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$ !he A(!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 )as dis(ussed in !he re'ious se(!ion*% !hen e'er# !i$e #our dialo" is dis$issed% !he s!a!e o+ !he Dialo" obHe(! is re!ained b# !he A(!i'i!#. I+ #ou de(ide !ha! #ou &ill no lon"er need !his obHe(! or i!Ms 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(! and i+ !he dialo" is sho&in"% i! &ill dis$iss i!. 9sing dismiss listeners I+ #ouMd li,e #our a l(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!ener in!er+a(e. This in!er+a(e has Hus! one $e!hod% onDis$iss)Dialo"In!er+a(e*% &hi(h &ill be (alled &hen !he dialo" is dis$issed. Then si$ l# ass #our OnDis$issLis!ener i$ le$en!a!ion !o se!OnDis$issLis!ener)*. >o&e'er% no!e !ha! dialo"s (an also be N(an(elled.N This is a s e(ial (ase !ha! indi(a!es !he dialo" &as ex li(i!l# (an(elled b# !he user. This &ill o((ur i+ !he user resses !he Nba(,N bu!!on !o (lose !he dialo"% or i+ !he dialo" ex li(i!l# (alls (an(el)* ) erha s +ro$ a N0an(elN bu!!on in !he dialo"*. When a dialo" is (an(elled% !he OnDis$issLis!ener &ill s!ill be no!i+ied% bu! i+ #ouMd li,e !o be in+or$ed !ha! !he dialo" &as ex li(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!h se!On0an(elLis!ener)*.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ;9
-reating an AlertDialog An Aler!Dialo" is an ex!ension o+ !he Dialo" (lass. I! is (a able o+ (ons!ru(!in" $os! dialo" user in!er+a(es and is !he su""es!ed dialo" !# e. Oou should use i! +or dialo"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 or radio bu!!ons*
To (rea!e an Aler!Dialo"% use !he Aler!Dialo".Builder sub(lass. Ge! a Builder &i!h Aler!Dialo".Builder)0on!ex!* and !hen use !he (lassMs ubli( $e!hods !o de+ine all o+ !he Aler!Dialo" ro er!ies. A+!er #ouMre done &i!h !he Builder% re!rie'e !he Aler!Dialo" obHe(! &i!h (rea!e)*. The +ollo&in" !o i(s sho& ho& !o de+ine 'arious ro er!ies o+ !he Aler!Dialo" usin" !he Aler!Dialo".Builder (lass. I+ #ou use an# o+ !he +ollo&in" sa$ le (ode inside #our on0rea!eDialo")* (allba(, $e!hod% #ou (an re!urn !he resul!in" Dialo" obHe(! !o dis la# !he dialo". Adding buttons
To (rea!e an Aler!Dialo" &i!h side1b#1side bu!!ons li,e !he one sho&n in !he s(reensho! !o !he ri"h!% use !he se!...Bu!!on)* $e!hodsK Aler!Dialo".Builder builder Y ne& Aler!Dialo".Builder)!his*J builder.se!Messa"e)NAre #ou sure #ou &an! !o exi!XN* .se!0an(elable)+alse* .se!Posi!i'eBu!!on)NOesN% ne& Dialo"In!er+a(e.On0li(,Lis!ener)* T ubli( 'oid on0li(,)Dialo"In!er+a(e dialo"% in! id* T M#A(!i'i!#.!his.+inish)*J W
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ;;
W* .se!Ne"a!i'eBu!!on)NNoN% ne& Dialo"In!er+a(e.On0li(,Lis!ener)* T ubli( 'oid on0li(,)Dialo"In!er+a(e dialo"% in! id* T dialo".(an(el)*J W W*J Aler!Dialo" aler! Y builder.(rea!e)*J Firs!% add a $essa"e +or !he dialo" &i!h se!Messa"e)0harSeEuen(e*. Then% be"in $e!hod1(hainin" and se! !he dialo" !o be not cancelable )so !he user (anno! (lose !he dialo" &i!h !he ba(, bu!!on* &i!h se!0an(elable)boolean*. For ea(h bu!!on% use one o+ !he se!...Bu!!on)* $e!hods% su(h as se!Posi!i'eBu!!on)*% !ha! a((e !s !he na$e +or !he bu!!on and a Dialo"In!er+a(e.On0li(,Lis!ener !ha! de+ines !he a(!ion !o !a,e &hen !he user sele(!s !he bu!!on. *ote: Oou (an onl# add one o+ ea(h bu!!on !# e !o !he Aler!Dialo". Tha! is% #ou (anno! ha'e $ore !han one N osi!i'eN bu!!on. This li$i!s !he nu$ber o+ ossible bu!!ons !o !hreeK osi!i'e% neu!ral% and ne"a!i'e. These na$es are !e(hni(all# irrele'an! !o !he a(!ual +un(!ionali!# o+ #our bu!!ons% bu! should hel #ou ,ee !ra(, o+ &hi(h one does &ha!. Adding a list
To (rea!e an Aler!Dialo" &i!h a lis! o+ sele(!able i!e$s li,e !he one sho&n !o !he ri"h!% use !he se!I!e$s)* $e!hodK +inal 0harSeEuen(e]^ i!e$s Y TNRedN% NGreenN% NBlueNWJ Aler!Dialo".Builder builder Y ne& Aler!Dialo".Builder)!his*J builder.se!Ti!le)NPi(, a (olorN*J builder.se!I!e$s)i!e$s% ne& Dialo"In!er+a(e.On0li(,Lis!ener)* T ubli( 'oid on0li(,)Dialo"In!er+a(e dialo"% in! i!e$* T
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ;B
Toas!.$a,eTex!)"e!A li(a!ion0on!ex!)*% i!e$s]i!e$^% Toas!.LENGT>ZS>ORT*.sho&)*J W W*J Aler!Dialo" aler! Y builder.(rea!e)*J Firs!% add a !i!le !o !he dialo" &i!h se!Ti!le)0harSeEuen(e*. Then% add a lis! o+ sele(!able i!e$s &i!h se!I!e$s)*% &hi(h a((e !s !he arra# o+ i!e$s !o dis la# and a Dialo"In!er+a(e.On0li(,Lis!ener !ha! de+ines !he a(!ion !o !a,e &hen !he user sele(!s an i!e$. Adding c)ec6bo0es and radio buttons
To (rea!e a lis! o+ $ul!i le1(hoi(e i!e$s )(he(,boxes* or sin"le1(hoi(e i!e$s )radio bu!!ons* inside !he dialo"% use !he se!Mul!i0hoi(eI!e$s)* and se!Sin"le0hoi(eI!e$s)* $e!hods% res e(!i'el#. I+ #ou (rea!e one o+ !hese sele(!able lis!s in !he on0rea!eDialo")* (allba(, $e!hod% Android $ana"es !he s!a!e o+ !he lis! +or #ou. As lon" as !he A(!i'i!# is a(!i'e% !he dialo" re$e$bers !he i!e$s !ha! &ere re'iousl# sele(!ed% bu! &hen !he user exi!s !he A(!i'i!#% !he sele(!ion is los!. *ote: To sa'e !he sele(!ion &hen !he user lea'es or auses !he A(!i'i!#% #ou $us! ro erl# sa'e and res!ore !he se!!in" !hrou"hou! !he A(!i'i!# Li+e(#(le. To er$anen!l# sa'e !he sele(!ions% e'en &hen !he A(!i'i!# ro(ess is (o$ le!el# shu!do&n% #ou need !o sa'e !he se!!in"s &i!h one o+ !he Da!a S!ora"e !e(hniEues. To (rea!e an Aler!Dialo" &i!h a lis! o+ sin"le1(hoi(e i!e$s li,e !he one sho&n !o !he ri"h!% use !he sa$e (ode +ro$ !he re'ious exa$ le% bu! re la(e !he se!I!e$s)* $e!hod &i!h se!Sin"le0hoi(eI!e$s)*K +inal 0harSeEuen(e]^ i!e$s Y TNRedN% NGreenN% NBlueNWJ Aler!Dialo".Builder builder Y ne& Aler!Dialo".Builder)!his*J builder.se!Ti!le)NPi(, a (olorN*J
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ;A
builder.se!Sin"le0hoi(eI!e$s)i!e$s% 1/% ne& Dialo"In!er+a(e.On0li(,Lis!ener)* T ubli( 'oid on0li(,)Dialo"In!er+a(e dialo"% in! i!e$* T Toas!.$a,eTex!)"e!A li(a!ion0on!ex!)*% i!e$s]i!e$^% Toas!.LENGT>ZS>ORT*.sho&)*J W W*J Aler!Dialo" aler! Y builder.(rea!e)*J The se(ond ara$e!er in !he se!Sin"le0hoi(eI!e$s)* $e!hod is an in!e"er 'alue +or !he checkedItem% &hi(h indi(a!es !he 6ero1based lis! osi!ion o+ !he de+aul! sele(!ed i!e$. Use N1/N !o indi(a!e !ha! no i!e$ should be sele(!ed b# de+aul!. -reating a "rogressDialog
A Pro"ressDialo" is an ex!ension o+ !he Aler!Dialo" (lass !ha! (an dis la# a ro"ress ani$a!ion in !he +or$ o+ a s innin" &heel% +or a !as, &i!h ro"ress !ha!Ms unde+ined% or a ro"ress bar% +or a !as, !ha! has a de+ined ro"ression. The dialo" (an also ro'ide bu!!ons% su(h as one !o (an(el a do&nload. O enin" a ro"ress dialo" (an be as si$ le as (allin" Pro"ressDialo".sho&)*. For exa$ le% !he ro"ress dialo" sho&n !o !he ri"h! (an be easil# a(hie'ed &i!hou! $ana"in" !he dialo" !hrou"h !he on0rea!eDialo")in!* (allba(,% as sho&n hereK Pro"ressDialo" dialo" Y Pro"ressDialo".sho&)M#A(!i'i!#.!his% NN% NLoadin". Please &ai!...N% !rue*J The +irs! ara$e!er is !he a li(a!ion 0on!ex!% !he se(ond is a !i!le +or !he dialo" )le+! e$ !#*% !he !hird is !he $essa"e% and !he las! ara$e!er is &he!her !he ro"ress is inde!er$ina!e )!his is onl# rele'an! &hen (rea!in" a ro"ress bar% &hi(h is dis(ussed in !he nex! se(!ion*. The de+aul! s!#le o+ a ro"ress dialo" is !he s innin" &heel. I+ #ou &an! !o (rea!e a ro"ress bar !ha! sho&s !he loadin" ro"ress &i!h "ranulari!#% so$e $ore (ode is reEuired% as dis(ussed in !he nex! se(!ion.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ;@
Pro"ressDialo")0on!ex!*. 8. Se! !he ro"ress s!#le !o NSTOLEZ>ORIFONTALN &i!h se!Pro"ressS!#le)in!* and se! an# o!her ro er!ies% su(h as !he $essa"e. =. When #ouMre read# !o sho& !he dialo"% (all sho&)* or re!urn !he Pro"ressDialo" +ro$ !he on0rea!eDialo")in!* (allba(,. ?. Oou (an in(re$en! !he a$oun! o+ ro"ress dis la#ed in !he bar b# (allin" ei!her se!Pro"ress)in!* &i!h a 'alue +or !he !o!al er(en!a"e (o$ le!ed so +ar or in(re$en!Pro"ressB#)in!* &i!h an in(re$en!al 'alue !o add !o !he !o!al er(en!a"e (o$ le!ed so +ar. For exa$ le% #our se!u $i"h! loo, li,e !hisK Pro"ressDialo" ro"ressDialo"J ro"ressDialo" Y ne& Pro"ressDialo")$0on!ex!*J ro"ressDialo".se!Pro"ressS!#le)Pro"ressDialo".STOLEZ>ORIFONTAL*J ro"ressDialo".se!Messa"e)NLoadin"...N*J ro"ressDialo".se!0an(elable)+alse*J The se!u is si$ le. Mos! o+ !he (ode needed !o (rea!e a ro"ress dialo" is a(!uall# in'ol'ed in !he ro(ess !ha! u da!es i!. Oou $i"h! +ind !ha! i!Ms ne(essar# !o (rea!e a se(ond !hread in #our a li(a!ion +or !his &or, and !hen re or! !he ro"ress ba(, !o !he A(!i'i!#Ms UI !hread &i!h a >andler obHe(!. I+ #ouMre no! +a$iliar &i!h usin" addi!ional !hreads &i!h a >andler% see !he exa$ le A(!i'i!# belo& !ha! uses a se(ond !hread !o in(re$en! a ro"ress dialo" $ana"ed b# !he A(!i'i!#.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e B<
-reating a -ustom Dialog I+ #ou &an! a (us!o$i6ed desi"n +or a dialo"% #ou (an (rea!e #our o&n la#ou! +or !he dialo" &indo& &i!h la#ou! and &id"e! ele$en!s. A+!er #ouM'e de+ined #our la#ou!% ass !he roo! 4ie& obHe(! or la#ou! resour(e ID !o se!0on!en!4ie&)4ie&*. For exa$ le% !o (rea!e !he dialo" sho&n !o !he ri"h!K /. 0rea!e an CML la#ou! sa'ed as (us!o$Zdialo".x$lK 8. QLinearLa#ou! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN =. androidKidYNVLid3la#ou!Zroo!N ?. androidKorien!a!ionYNhori6on!alN 9. androidKla#ou!Z&id!hYN+illZ aren!N ;. androidKla#ou!Zhei"h!YN+illZ aren!N B. androidK addin"YN/<d N A. : @. QI$a"e4ie& androidKidYNVLid3i$a"eN /<. androidKla#ou!Z&id!hYN&ra Z(on!en!N //. androidKla#ou!Zhei"h!YN+illZ aren!N /8. androidKla#ou!Z$ar"inRi"h!YN/<d N /=. 3: /?. QTex!4ie& androidKidYNVLid3!ex!N /9. androidKla#ou!Z&id!hYN&ra Z(on!en!N /;. androidKla#ou!Zhei"h!YN+illZ aren!N /B. androidK!ex!0olorYN2FFFN /A. 3: /@.Q3LinearLa#ou!: This CML de+ines an I$a"e4ie& and a Tex!4ie& inside a LinearLa#ou!. 8<.Se! !he abo'e la#ou! as !he dialo"Ms (on!en! 'ie& and de+ine !he (on!en! +or !he I$a"e4ie& and Tex!4ie& ele$en!sK 8/.0on!ex! $0on!ex! Y "e!A li(a!ion0on!ex!)*J 88.Dialo" dialo" Y ne& Dialo")$0on!ex!*J 8=. 8?.dialo".se!0on!en!4ie&)R.la#ou!.(us!o$Zdialo"*J 89.dialo".se!Ti!le)N0us!o$ Dialo"N*J 8;.Tex!4ie& !ex! Y )Tex!4ie&* dialo".+ind4ie&B#Id)R.id.!ex!*J 8B.!ex!.se!Tex!)N>ello% !his is a (us!o$ dialo"[N*J
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e B/
8A.I$a"e4ie& i$a"e Y )I$a"e4ie&* dialo".+ind4ie&B#Id)R.id.i$a"e*J 8@.i$a"e.se!I$a"eResour(e)R.dra&able.android*J A+!er #ou ins!an!ia!e !he Dialo"% se! #our (us!o$ la#ou! as !he dialo"Ms (on!en! 'ie& &i!h se!0on!en!4ie&)in!*% assin" i! !he la#ou! resour(e ID. No& !ha! !he Dialo" has a de+ined la#ou!% #ou (an (a !ure 4ie& obHe(!s +ro$ !he la#ou! &i!h +ind4ie&B#Id)in!* and $odi+# !heir (on!en!.
=<. Tha!Ms i!. Oou (an no& sho& !he dialo" as des(ribed in Sho&in" A Dialo".
A dialo" $ade &i!h !he base Dialo" (lass $us! ha'e a !i!le. I+ #ou donM! (all se!Ti!le)*% !hen !he s a(e used +or !he !i!le re$ains e$ !#% bu! s!ill 'isible. I+ #ou donM! &an! a !i!le a! all% !hen #ou should (rea!e #our (us!o$ dialo" usin" !he Aler!Dialo" (lass. >o&e'er% be(ause an Aler!Dialo" is (rea!ed easies! &i!h !he Aler!Dialo".Builder (lass% #ou do no! ha'e a((ess !o !he se!0on!en!4ie&)in!* $e!hod used abo'e. Ins!ead% #ou $us! use se!4ie&)4ie&*. This $e!hod a((e !s a 4ie& obHe(!% so #ou need !o in+la!e !he la#ou!Ms roo! 4ie& obHe(! +ro$ CML. To in+la!e !he CML la#ou!% re!rie'e !he La#ou!In+la!er &i!h "e!La#ou!In+la!er)* )or "e!S#s!e$Ser'i(e)**% and !hen (all in+la!e)in!% 4ie&Grou *% &here !he +irs! ara$e!er is !he la#ou! resour(e ID and !he se(ond is !he ID o+ !he roo! 4ie&. A! !his oin!% #ou (an use !he in+la!ed la#ou! !o +ind 4ie& obHe(!s in !he la#ou! and de+ine !he (on!en! +or !he I$a"e4ie& and Tex!4ie& ele$en!s. Then ins!an!ia!e !he Aler!Dialo".Builder and se! !he in+la!ed la#ou! +or !he dialo" &i!h se!4ie&)4ie&*. >ereMs an exa$ le% (rea!in" a (us!o$ la#ou! in an Aler!Dialo"K Aler!Dialo".Builder builderJ Aler!Dialo" aler!Dialo"J 0on!ex! $0on!ex! Y "e!A li(a!ion0on!ex!)*J La#ou!In+la!er in+la!er Y )La#ou!In+la!er* $0on!ex!."e!S#s!e$Ser'i(e)LAOOUTZINFLATER*J 4ie& la#ou! Y in+la!er.in+la!e)R.la#ou!.(us!o$Zdialo"% )4ie&Grou * +ind4ie&B#Id)R.id.la#ou!Zroo!**J Tex!4ie& !ex! Y )Tex!4ie&* la#ou!.+ind4ie&B#Id)R.id.!ex!*J !ex!.se!Tex!)N>ello% !his is a (us!o$ dialo"[N*J I$a"e4ie& i$a"e Y )I$a"e4ie&* la#ou!.+ind4ie&B#Id)R.id.i$a"e*J i$a"e.se!I$a"eResour(e)R.dra&able.android*J
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e B8
Dialogs.0ample:5
AlertDialog .0:5 alertdialog%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: QLinearLa#ou! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N: QBu!!on androidK!ex!YNAler! Dialo"N
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e B=
androidKon0li(,YNaler!Fun(!ionN androidKidYNVLid3aler!Bu!!onN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N3: Q3LinearLa#ou!: AlertDialogDemo%java a(,a"e (o$.dialo"J i$ i$ i$ i$ i$ i$ or! android.a .A(!i'i!#J or! android.a .Aler!Dialo"J or! android.(on!en!.Dialo"In!er+a(eJ or! android.os.BundleJ or! android.'ie&.4ie&J or! android.&id"e!.Toas!J
ubli( (lass Aler!Dialo"De$o ex!ends A(!i'i!# T VO'erride ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T su er.on0rea!e)sa'edIns!an(eS!a!e*J se!0on!en!4ie&)R.la#ou!.aler!dialo"*J W ubli( 'oid aler!Fun(!ion)4ie& '*T Aler!Dialo".Builder aler!box Y ne& Aler!Dialo".Builder)!his*J 33 se! !he $essa"e !o dis la# aler!box.se!Messa"e)NThis is !he aler!box[N*J aler!box.se!Ti!le)NAler! Ms"N*J aler!box.se!Neu!ralBu!!on)N0an(elN% ne& Dialo"In!er+a(e.On0li(,Lis!ener)* 33 (li(, lis!ener on !he aler! box ubli( 'oid on0li(,)Dialo"In!er+a(e d% in! id* T 33 !he bu!!on &as (li(,ed Toas!.$a,eTex!)"e!A li(a!ion0on!ex!)*% N0an(el bu!!on (li(,edN% Toas!.LENGT>ZLONG*.sho&)*J W
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e B?
W*J aler!box.se!Posi!i'eBu!!on)NOesN% ne& Dialo"In!er+a(e.On0li(,Lis!ener)* T 33 (li(, lis!ener on !he aler! box ubli( 'oid on0li(,)Dialo"In!er+a(e d% in! id* T 33 !he bu!!on &as (li(,ed Toas!.$a,eTex!)"e!A li(a!ion0on!ex!)*% NOes bu!!on (li(,edN% Toas!.LENGT>ZLONG*.sho&)*J W W*J aler!box.se!Ne"a!i'eBu!!on)NNoN% ne& Dialo"In!er+a(e.On0li(,Lis!ener)* T 33 (li(, lis!ener on !he aler! box ubli( 'oid on0li(,)Dialo"In!er+a(e d% in! id* T 33 !he bu!!on &as (li(,ed Toas!.$a,eTex!)"e!A li(a!ion0on!ex!)*% NNo bu!!on (li(,edN% Toas!.LENGT>ZLONG*.sho&)*J W W*J aler!box.se!0an(elable)!rue*J aler!box.sho&)*J W W "rogressDialog .0:5 progressdialog%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: QLinearLa#ou! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N: QBu!!on androidK!ex!YNPro"resss Dialo"N androidKon0li(,YN ro"ressFun(!ionN androidKidYNVLid3 ro"ressBu!!onN
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e B9
"rogressDialogDemo%java a(,a"e (o$.dialo"J i$ i$ i$ i$ or! android.a .A(!i'i!#J or! android.a .Pro"ressDialo"J or! android.os.BundleJ or! android.'ie&.4ie&J
ubli( (lass Pro"ressDialo"De$o ex!ends A(!i'i!# T VO'erride ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T su er.on0rea!e)sa'edIns!an(eS!a!e*J se!0on!en!4ie&)R.la#ou!. ro"ressdialo"*J W ubli( 'oid ro"ressFun(!ion)4ie& '*T Pro"ressDialo" dialo" Y ne& Pro"ressDialo")!his*J 33 $a,e !he ro"ress bar (an(el dialo".se!0an(elable)!rue*J 33 se! a $essa"e !ex! dialo".se!Messa"e)NLoadin"...N*J 33Se!!in" !he s!#les as hori6on!al 33 dialo".se!Pro"ressS!#le)Pro"ressDialo".STOLEZ>ORIFONTAL*J
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e B;
Date"ic6erDialog .0:5 datepic6erdialog%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: QLinearLa#ou! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N: QBu!!on androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidK!ex!YNSho& da!eN androidKidYNVLid3bu!!on/N3: Q3LinearLa#ou!:
Date"ic6erActivityDemo%java a(,a"e (o$.dialo"J i$ i$ i$ i$ i$ i$ or! Ha'a.u!il.0alendarJ or! android.a .A(!i'i!#J or! android.a .Da!ePi(,erDialo"J or! android.a .Dialo"J or! android.'ie&.4ie&J or! android.&id"e!.Bu!!onJ
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e BB
i$ or! android.&id"e!.Da!ePi(,erJ i$ or! android.&id"e!.Toas!J i$ or! android.os.BundleJ ubli( (lass Da!ePi(,erA(!i'i!#De$o ex!ends A(!i'i!# i$ le$en!s Bu!!on.On0li(,Lis!ener T ri'a!e Bu!!on b/J s!a!i( +inal in! DATEZDIALOGZID Y <J VO'erride ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T su er.on0rea!e)sa'edIns!an(eS!a!e*J se!0on!en!4ie&)R.la#ou!.da!e i(,er*J 33 Addin" bu!!on !o !he la#ou! b/Y)Bu!!on*+ind4ie&B#Id)R.id.bu!!on/*J b/.se!On0li(,Lis!ener)!his*J W ubli( 'oid on0li(,)4ie& '* T sho&Dialo")DATEZDIALOGZID*J W 33 0rea!in" dialo" VO'erride ro!e(!ed Dialo" on0rea!eDialo")in! id* T 0alendar ( Y 0alendar."e!Ins!an(e)*J in! (#ear Y (."e!)0alendar.OEAR*J in! ($on!h Y (."e!)0alendar.MONT>*J in! (da# Y (."e!)0alendar.DAOZOFZMONT>*J 33re!urn ne& Da!ePi(,erDialo")!his% null% /@@@% <% =/*J re!urn ne& Da!ePi(,erDialo")!his% da!eLis!ener% (#ear% ($on!h% (da#*J W Da!ePi(,erDialo".OnDa!eSe!Lis!ener da!eLis!ener Y ne& Da!ePi(,erDialo".OnDa!eSe!Lis!ener)* T 33 onDa!eSe! $e!hod ubli( 'oid onDa!eSe!)Da!ePi(,er 'ie&% in! #ear% in! $on!hO+Oear% in!
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e BA
da#O+Mon!h* T S!rin" da!eZsele(!ed Y S!rin".'alueO+)$on!hO+OearL/*LN 3NL S!rin".'alueO+)da#O+Mon!h*LN 3NLS!rin".'alueO+)#ear*J Toas!.$a,eTex!)Da!ePi(,erA(!i'i!#De$o.!his% NSele(!ed Da!e is YNLda!eZsele(!ed% Toas!.LENGT>ZS>ORT*.sho&)*J W WJ W
,ime"ic6erDialog .0:5 timepic6erdialog%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: QLinearLa#ou! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N: QBu!!on androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidK!ex!YNSho& !i$eN androidKidYNVLid3!i$eBu!N3: Q3LinearLa#ou!: ,ime"ic6erDemo%java a(,a"e (o$.dialo"J i$ i$ i$ i$ i$ or! Ha'a.u!il.0alendarJ or! android.a .A(!i'i!#J or! android.a .Dialo"J or! android.a .Ti$ePi(,erDialo"J or! android.'ie&.4ie&J
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e B@
i$ i$ i$ i$
ubli( (lass Ti$ePi(,erDe$o ex!ends A(!i'i!# T ri'a!e Bu!!on b/J s!a!i( +inal in! TIMEZDIALOGZID Y <J VO'erride ro!e(!ed 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T su er.on0rea!e)sa'edIns!an(eS!a!e*J se!0on!en!4ie&)R.la#ou!.!i$e i,er*J b/ Y )Bu!!on* +ind4ie&B#Id)R.id.!i$eBu!*J b/.se!On0li(,Lis!ener)ne& 4ie&.On0li(,Lis!ener)* T ubli( 'oid on0li(,)4ie& '* T sho&Dialo")TIMEZDIALOGZID*J W W*J W VO'erride ro!e(!ed Dialo" on0rea!eDialo")in! id* T 0alendar ( Y 0alendar."e!Ins!an(e)*J in! (hour Y (."e!)0alendar.>OURZOFZDAO*J in! ($onu!e Y (."e!)0alendar.MINUTE*J s&i!(h )id* T (ase TIMEZDIALOGZIDK re!urn ne& Ti$ePi(,erDialo")!his% $Ti$eSe!Lis!ener% (hour% ($onu!e% +alse*J W re!urn nullJ
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e A<
W Ti$ePi(,erDialo".OnTi$eSe!Lis!ener $Ti$eSe!Lis!ener Y ne& Ti$ePi(,erDialo".OnTi$eSe!Lis!ener)* T ubli( 'oid onTi$eSe!)Ti$ePi(,er 'ie&% in! hourO+Da#% in! $inu!e* T Toas!.$a,eTex!)Ti$ePi(,erDe$o.!his% NTi$e isYNLhourO+Da#LNKNL$inu!e% Toas!.LENGT>ZS>ORT*.sho&)*J W WJ W -ustom Dialog .0ample :5
main%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: QLinearLa#ou! androidKidYNVLid3LinearLa#ou!</N androidKla#ou!Zhei"h!YN+illZ aren!N x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKba(,"roundYNVdra&able3b"ZandroidN androidKorien!a!ionYN'er!i(alN androidK"ra'i!#YN(en!erN androidKla#ou!Z&id!hYN8<<di N:
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e A/
QTex!4ie& androidKidYNVLid3!ex!4ie&/N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidKla#ou!Z&id!hYN&ra Z(on!en!N androidK!ex!YN Android 0us!o$ Dialo"N3: QTex!4ie& androidKidYNVLid3!ex!4ie&8N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidKla#ou!Z&id!hYN&ra Z(on!en!N androidK!ex!YN0us!o$ Dialo" Exa$ le B# iMobi!e,N androidK"ra'i!#YN(en!erN3: QBu!!on androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidK!ex!YNO5N androidKidYNVLid3O,Bu!!onN3: Q3LinearLa#ou!: -ustomi<eDialog%java a(,a"e (o$.(us!o$dialo"J i$ i$ i$ i$ i$ i$ i$ or! (o$.(us!o$dialo".RJ or! android.a .Dialo"J or! android.(on!en!.0on!ex!J or! android.'ie&.4ie&J or! android.'ie&.Windo&J or! android.'ie&.4ie&.On0li(,Lis!enerJ or! android.&id"e!.Bu!!onJ
3UU 0lass Mus! ex!ends &i!h Dialo" U3 3UU I$ le$en! on0li(,Lis!ener !o dis$iss dialo" &hen O5 Bu!!on is ressed U3 ubli( (lass 0us!o$i6eDialo" ex!ends Dialo" i$ le$en!s On0li(,Lis!ener T Bu!!on o,Bu!!onJ ubli( 0us!o$i6eDialo")0on!ex! (on!ex!* T su er)(on!ex!*J 33 Desi"n !he dialo" in $ain.x$l +ile se!0on!en!4ie&)R.la#ou!.$ain*J
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e A8
o,Bu!!on Y )Bu!!on* +ind4ie&B#Id)R.id.O,Bu!!on*J o,Bu!!on.se!On0li(,Lis!ener)!his*J W ubli( 'oid on0li(,)4ie& '* T 3UU When O5 Bu!!on is (li(,ed% dis$iss !he dialo" U3 i+ )' YY o,Bu!!on* dis$iss)*J W W
-ustomDialog.0ample%java
a(,a"e (o$.(us!o$dialo"J i$ or! android.a .A(!i'i!#J i$ or! android.os.BundleJ ubli( (lass 0us!o$Dialo"Exa$ le ex!ends A(!i'i!# T VO'erride ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T su er.on0rea!e)sa'edIns!an(eS!a!e*J 3UU Dis la# 0us!o$ Dialo" U3 0us!o$i6eDialo" (us!o$i6eDialo" Y ne& 0us!o$i6eDialo")!his*J (us!o$i6eDialo".sho&)*J W W -reating enus
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e A=
Menus are an i$ or!an! ar! o+ an# a li(a!ion. The# ro'ide +a$iliar in!er+a(es !ha! re'eal a li(a!ion +un(!ions and se!!in"s. Android o++ers an eas# ro"ra$$in" in!er+a(e +or de'elo ers !o ro'ide s!andardi6ed a li(a!ion $enus +or 'arious si!ua!ions. Android offers t)ree fundamental types of application menus: Options enu
This is !he ri$ar# se! o+ $enu i!e$s +or an A(!i'i!#. I! is re'ealed b# ressin" !he de'i(e MENU ,e#. Wi!hin !he O !ions Menu are !&o "rou s o+ $enu i!e$sK Icon enu This is !he (olle(!ion o+ i!e$s ini!iall# 'isible a! !he bo!!o$ o+ !he s(reen a! !he ress o+ !he MENU ,e#. I! su or!s a $axi$u$ o+ six $enu i!e$s. These are !he onl# $enu i!e$s !ha! su or! i(ons and !he onl# $enu i!e$s !ha! do no! su or! (he(,boxes or radio bu!!ons. Ex anded Menu This is a 'er!i(al lis! o+ i!e$s ex osed b# !he NMoreN $enu i!e$ +ro$ !he I(on Menu. I! exis!s onl# &hen !he I(on Menu be(o$es o'er1loaded and is (o$ rised o+ !he six!h O !ion Menu i!e$ and !he res!. -onte0t enu This is a +loa!in" lis! o+ $enu i!e$s !ha! $a# a ear &hen #ou er+or$ a lon"1 ress on a 4ie& )su(h as a lis! i!e$*. Submenu This is a +loa!in" lis! o+ $enu i!e$s !ha! is re'ealed b# an i!e$ in !he O !ions Menu or a 0on!ex! Menu. A Sub$enu i!e$ (anno! su or! nes!ed Sub$enus. The add)* $e!hod used in !his sa$ le !a,es +our ar"u$en!sK "rou Id% i!e$Id% order% and !i!le. The "rou Id allo&s #ou !o asso(ia!e !his $enu i!e$ &i!h a "rou o+ o!her i!e$s
Options
enu
The O !ions Menu is o ened b# ressin" !he de'i(e MENU ,e#. When o ened% !he I(on Menu is dis la#ed% &hi(h holds !he +irs! six $enu i!e$s. I+ $ore !han six i!e$s are added !o !he O !ions Menu% !hen !hose !ha! (anM! +i! in !he I(on
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e A?
Menu are re'ealed in !he Ex anded Menu% 'ia !he NMoreN $enu i!e$. The Ex anded Menu is au!o$a!i(all# added &hen !here are $ore !han six i!e$s. The O !ions Menu is &here #ou should in(lude basi( a li(a!ion +un(!ions and an# ne(essar# na'i"a!ion i!e$s )e.".% !o a ho$e s(reen or a li(a!ion se!!in"s*. Oou (an also add Sub$enus +or or"ani6in" !o i(s and in(ludin" ex!ra $enu +un(!ionali!#. When !his $enu is o ened +or !he +irs! !i$e% !he Android s#s!e$ &ill (all !he A(!i'i!# on0rea!eO !ionsMenu)* (allba(, $e!hod. O'erride !his $e!hod in #our A(!i'i!# and o ula!e !he Menu obHe(! "i'en !o #ou. Oou (an o ula!e !he $enu b# in+la!in" a $enu resour(e !ha! &as de+ined in CML% or b# (allin" add)* +or ea(h i!e$ #ouMd li,e in !he $enu. This $e!hod adds a MenuI!e$% and re!urns !he ne&l# (rea!ed obHe(! !o #ou. Oou (an use !he re!urned MenuI!e$ !o se! addi!ional ro er!ies li,e an i(on% a ,e#board shor!(u!% an in!en!% and o!her se!!in"s +or !he i!e$. There are $ul!i le add)* $e!hods. Usuall#% #ouMll &an! !o use one !ha! a((e !s an i!e$Id ar"u$en!. This is a uniEue in!e"er !ha! allo&s #ou !o iden!i+# !he i!e$ durin" a (allba(,. When a $enu i!e$ is sele(!ed +ro$ !he O !ions Menu% #ou &ill re(ie'e a (allba(, !o !he onO !ionsI!e$Sele(!ed)* $e!hod o+ #our A(!i'i!#. This (allba(, asses #ou !he MenuI!e$ !ha! has been sele(!ed. Oou (an iden!i+# !he i!e$ b# reEues!in" !he i!e$Id% &i!h "e!I!e$Id)*% &hi(h re!urns !he in!e"er !ha! &as assi"ned &i!h !he add)* $e!hod. On(e #ou iden!i+# !he $enu i!e$% #ou (an !a,e !he a ro ria!e a(!ion. >ereMs an exa$ le o+ !his ro(edure% inside an A(!i'i!#% &herein &e (rea!e an O !ions Menu and handle i!e$ sele(!ionsK 3U 0rea!es !he $enu i!e$s U3 ubli( boolean on0rea!eO !ionsMenu)Menu $enu* T $enu.add)<% MENUZNEWZGAME% <% NNe& Ga$eN*J $enu.add)<% MENUZDUIT% <% NDui!N*J re!urn !rueJ W 3U >andles i!e$ sele(!ions U3 ubli( boolean onO !ionsI!e$Sele(!ed)MenuI!e$ i!e$* T
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e A9
s&i!(h )i!e$."e!I!e$Id)** T (ase MENUZNEWZGAMEK ne&Ga$e)*J re!urn !rueJ (ase MENUZDUITK Eui!)*J re!urn !rueJ W re!urn +alseJ W
The add)* $e!hod used in !his sa$ le !a,es +our ar"u$en!sK "rou Id% i!e$Id% order% and !i!le. The "rou Id allo&s #ou !o asso(ia!e !his $enu i!e$ &i!h a "rou o+ o!her i!e$s )$ore abou! Menu "rou s* P in !his exa$ le% &e i"nore i!. i!e$Id is a uniEue in!e"er !ha! &e "i'e !he MenuI!e$ so !ha! (an iden!i+# i! in !he nex! (allba(,. order allo&s us !o de+ine !he dis la# order o+ !he i!e$ P b# de+aul!% !he# are dis la#ed b# !he order in &hi(h &e add !he$. !i!le is% o+ (ourse% !he na$e !ha! "oes on !he $enu i!e$ )!his (an also be a s!rin" resour(e% and &e re(o$$end #ou do i! !ha! &a# +or easier lo(ali6a!ion*. Ti K I+ #ou ha'e se'eral $enu i!e$s !ha! (an be "rou ed !o"e!her &i!h a !i!le% (onsider or"ani6in" !he$ in!o a Sub$enu. Addin" i(ons I(ons (an also be added !o i!e$s !ha! a ears in !he I(on Menu &i!h se!I(on)*.
For exa$ leK $enu.add)<% MENUZDUIT% <% NDui!N* .se!I(on)R.dra&able.$enuZEui!Zi(on*J Modi+#in" !he $enu I+ #ou &an! !o so$e!i$es re1&ri!e !he O !ions Menu as i! is o ened% o'erride !he onPre areO !ionsMenu)* $e!hod% &hi(h is (alled ea(h !i$e !he $enu is o ened. This &ill ass #ou !he Menu obHe(!% Hus! li,e !he on0rea!eO !ionsMenu)* (allba(,.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e A;
This is use+ul i+ #ouMd li,e !o add or re$o'e $enu o !ions de endin" on !he (urren! s!a!e o+ an a li(a!ion or "a$e. No!eK When (han"in" i!e$s in !he $enu% i!Ms bad ra(!i(e !o do so based on !he (urren!l# sele(!ed i!e$. 5ee in $ind !ha!% &hen in !ou(h $ode% !here &ill no! be a sele(!ed )or +o(used* i!e$. Ins!ead% #ou should use a 0on!ex! Menu +or su(h beha'iors% &hen #ou &an! !o ro'ide +un(!ionali!# based on a ar!i(ular i!e$ in !he UI. -onte0t enu
The Android (on!ex! $enu is si$ilar% in (on(e !% !o !he $enu re'ealed &i!h a Nri"h!1(li(,N on a P0. When a 'ie& is re"is!ered !o a (on!ex! $enu% er+or$in" a Nlon"1 ressN ) ress and hold +or abou! !&o se(onds* on !he obHe(! &ill re'eal a +loa!in" $enu !ha! ro'ides +un(!ions rela!in" !o !ha! i!e$. 0on!ex! $enus (an be re"is!ered !o an# 4ie& obHe(!% ho&e'er% !he# are $os! o+!en used +or i!e$s in a Lis!4ie&% &hi(h hel +ull# indi(a!es !he resen(e o+ !he (on!ex! $enu b# !rans+or$in" !he ba(,"round (olor o+ !he Lis!4ie& i!e$ &hen ressed. )The i!e$s in !he honeMs (on!a(! lis! o++er an exa$ le o+ !his +ea!ure.* No!eK 0on!ex! $enu i!e$s do no! su or! i(ons or shor!(u! ,e#s.
To (rea!e a (on!ex! $enu% #ou $us! o'erride !he A(!i'i!#Ms (on!ex! $enu (allba(, $e!hodsK on0rea!e0on!ex!Menu)* and on0on!ex!I!e$Sele(!ed)*. Inside !he on0rea!e0on!ex!Menu)* (allba(, $e!hod% #ou (an add $enu i!e$s usin" one o+ !he add)* $e!hods% or b# in+la!in" a $enu resour(e !ha! &as de+ined in CML. Then% re"is!er a 0on!ex!Menu +or !he 4ie&% &i!h re"is!erFor0on!ex!Menu)*.
i$ or! android.'ie&.4ie&J i$ or! android.'ie&.0on!ex!Menu.0on!ex!MenuIn+oJ i$ or! android.&id"e!.Bu!!onJ i$ or! android.&id"e!.Toas!J ubli( (lass 0on!ex!MenuDe$o ex!ends A(!i'i!# T Bu!!on b!nJ VO'erride ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T su er.on0rea!e)sa'edIns!an(eS!a!e*J se!0on!en!4ie&)R.la#ou!.$ain*J b!n Y )Bu!!on* +ind4ie&B#Id)R.id.0on!ex!Bu!!on*J 33re"is!er !he bu!!on &i!h (on!ex! $enu re"is!erFor0on!ex!Menu)b!n*J W VO'erride ubli( 'oid on0rea!e0on!ex!Menu)0on!ex!Menu $enu% 4ie& '%0on!ex!MenuIn+o $enuIn+o* T su er.on0rea!e0on!ex!Menu)$enu% '% $enuIn+o*J $enu.se!>eaderTi!le)N0on!ex! MenuN*J $enu.add)<% '."e!Id)*% <% NA(!ion /N*J $enu.add)<% '."e!Id)*% <% NA(!ion 8N*J SubMenu s$Y$enu.addSubMenu)NFileN*.se!I(on)R.dra&able.i(on*J
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e AA
s$.add)NO enN*J s$.add)N0loseN*J s$.add)<% '."e!Id)*%<%NNe&N*J W VO'erride ubli( boolean on0on!ex!I!e$Sele(!ed)MenuI!e$ i!e$* T i+)i!e$."e!Ti!le)*YYNA(!ion /N*T +un(!ion/)i!e$."e!I!e$Id)**J W else i+)i!e$."e!Ti!le)*YYNA(!ion 8N*T +un(!ion8)i!e$."e!I!e$Id)**J W else i+)i!e$."e!Ti!le)*YYNNe&N*T +un(!ion=)i!e$."e!I!e$Id)**J W else Tre!urn +alseJW re!urn !rueJ W ubli( 'oid +un(!ion/)in! id*T Toas!.$a,eTex!)!his% N+un(!ion / (alledN% Toas!.LENGT>ZS>ORT*.sho&)*J W
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e A@
ubli( 'oid +un(!ion8)in! id*T Toas!.$a,eTex!)!his% N+un(!ion 8 (alledN% Toas!.LENGT>ZS>ORT*.sho&)*J W ubli( 'oid +un(!ion=)in! id*T Toas!.$a,eTex!)!his% N+un(!ion = (alledN% Toas!.LENGT>ZS>ORT*.sho&)*J W W In on0rea!e0on!ex!Menu)*% &e are "i'en no! onl# !he 0on!ex!Menu !o &hi(h &e &ill add MenuI!e$s% bu! also !he 4ie& !ha! &as sele(!ed and a 0on!ex!MenuIn+o obHe(!% &hi(h ro'ides addi!ional in+or$a!ion abou! !he obHe(! !ha! &as sele(!ed. In !his exa$ le% no!hin" s e(ial is done in on0rea!e0on!ex!Menu)* P Hus! a (ou le i!e$s are added as usual. In !he on0on!ex!I!e$Sele(!ed)* (allba(,% &e reEues! !he Ada !er0on!ex!MenuIn+o +ro$ !he MenuI!e$% &hi(h ro'ides in+or$a!ion abou! !he (urren!l# sele(!ed i!e$. All &e need +ro$ !his is !he lis! ID +or !he sele(!ed i!e$% so &he!her edi!in" a no!e or dele!in" i!% &e +ind !he ID &i!h !he Ada !er0on!ex!MenuIn+o.in+o +ield o+ !he obHe(!. This ID is assed !o !he edi!No!e)* and dele!eNo!e)* $e!hods !o er+ro$ !he res e(!i'e a(!ion. No&% !o re"is!er !his (on!ex! $enu +or all !he i!e$s in a Lis!4ie&% &e ass !he en!ire Lis!4ie& !o !he re"is!erFor0on!ex!Menu)4ie&* $e!hodK re"is!erFor0on!ex!Menu)"e!Lis!4ie&)**J Re$e$ber% #ou (an ass an# 4ie& obHe(! !o re"is!er a (on!ex! $enu. >ere% "e!Lis!4ie&)* re!urns !he Lis!4ie& obHe(! used in !he No!e ad a li(a!ionMs Lis!A(!i'i!#. As su(h% ea(h i!e$ in !he lis! is re"is!ered !o !his (on!ex! $enu. Sub$enus A sub $enu (an be added &i!hin an# $enu% ex(e ! ano!her sub $enu. These are 'er# use+ul &hen #our a li(a!ion has a lo! o+ +un(!ions !ha! $a# be or"ani6ed in
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e @<
!o i(s% li,e !he i!e$s in a P0 a li(a!ionMs $enu bar )File% Edi!% 4ie&% e!(.*. A sub $enu is (rea!ed b# addin" i! !o an exis!in" Menu &i!h addSubMenu)*. This re!urns a SubMenu obHe(! )an ex!ension o+ Menu*. Oou (an !hen add addi!ional i!e$s !o !his $enu% &i!h !he nor$al rou!ine% usin" !he add)* $e!hods. For exa$ leK ubli( boolean on0rea!eO !ionsMenu)Menu $enu* T boolean resul! Y su er.on0rea!eO !ionsMenu)$enu*J SubMenu +ileMenu Y $enu.addSubMenu)NFileN*J SubMenu edi!Menu Y $enu.addSubMenu)NEdi!N*J +ileMenu.add)Nne&N*J +ileMenu.add)No enN*J +ileMenu.add)Nsa'eN*J edi!Menu.add)NundoN*J re!urn resul!J W 0allba(,s +or i!e$s sele(!ed in a sub $enu are $ade !o !he aren! $enuMs (allba(, $e!hod. For !he exa$ le abo'e% sele(!ions in !he sub $enu &ill be handled b# !he onO !ionsI!e$Sele(!ed)* (allba(,. Oou (an also add Sub$enus &hen #ou de+ine !he aren! $enu in CML. De+ine Menus in CML Gus! li,e Android UI la#ou!s% #ou (an de+ine a li(a!ion $enus in CML% !hen in+la!e !he$ in #our $enuMs on0rea!e...)* (allba(, $e!hod. This $a,es #our a li(a!ion (ode (leaner and se ara!es $ore in!er+a(e desi"n in!o CML% &hi(h is easier !o 'isuali6e. To s!ar!% (rea!e a ne& +older in #our roHe(! res3 dire(!or# (alled $enu. This is &here #ou should ,ee all CML +iles !ha! de+ine #our a li(a!ion $enus. In a $enu CML la#ou!% !here are !hree 'alid ele$en!sK Q$enu:% Q"rou : and Qi!e$:. The i!e$ and "rou ele$en!s $us! be (hildren o+ a $enu% bu! i!e$ ele$en!s $a# also be !he (hildren o+ a "rou % and ano!her $enu ele$en! $a# be !he (hild o+ an i!e$ )!o (rea!e a Sub$enu*. O+ (ourse% !he roo! node o+ an# +ile $us! be a $enu ele$en!.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e @/
As an exa$ le% &eMll de+ine !he sa$e $enu (rea!ed in !he O !ions Menu se(!ion% abo'e. We s!ar! &i!h an CML +ile na$ed o !ionsZ$enu.x$l inside !he res3$enu3 +olderK Q$enu x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN: Qi!e$ androidKidYNVLid3ne&Z"a$eN androidK!i!leYNNe& Ga$eN 3: Qi!e$ androidKidYNVLid3Eui!N androidK!i!leYNDui!N 3: Q3$enu: Then% in !he on0rea!eO !ionsMenu)* $e!hod% &e in+la!e !his resour(e usin" MenuIn+la!er.in+la!e)*K ubli( boolean on0rea!eO !ionsMenu)Menu $enu* T MenuIn+la!er in+la!er Y "e!MenuIn+la!er)*J in+la!er.in+la!e)R.$enu.o !ionsZ$enu% $enu*J re!urn !rueJ W The "e!MenuIn+la!er)* $e!hod re!urns !he MenuIn+la!er +or our a(!i'i!#Ms (on!ex!. We !hen (all in+la!e)*% assin" i! a oin!er !o our $enu resour(e and !he Menu obHe(! "i'en b# !he (allba(,.
Menu "rou s When addin" ne& i!e$s !o a $enu% #ou (an o !ionall# in(lude ea(h i!e$ in a "rou . A $enu "rou is a (olle(!ion o+ $enu i!e$s !ha! (an share (er!ain !rai!s% li,e &he!her !he# are 'isible% enabled% or (he(,able. A "rou is de+ined b# an in!e"er )or a resour(e id% in CML*. A $enu i!e$ is added !o !he "rou &hen i! is
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e @8
added !o !he $enu% usin" one o+ !he add)* $e!hods !ha! a((e !s a "rou Id as an ar"u$en!% su(h as add)in!% in!% in!% in!*. Oou (an sho& or hide !he en!ire "rou &i!h se!Grou 4isible)*J enable or disable !he "rou &i!h se!Grou Enabled)*J and se! &he!her !he i!e$s (an be (he(,able &i!h se!Grou 0he(,able)*. -)ec6able menu items An# $enu i!e$ (an be used as an in!er+a(e +or !urnin" o !ions on and o++. This (an be indi(a!ed &i!h a (he(,box +or s!and1alone o !ions% or radio bu!!ons +or "rou s o+ $u!uall# exlusi'e o !ions )see !he s(reensho!% !o !he ri"h!*. No!eK Menu i!e$s in !he I(on Menu (anno! dis la# a (he(,box or radio bu!!on. I+ #ou (hoose !o $a,e i!e$s in !he I(on Menu (he(,able% !hen #ou $us! ersonall# indi(a!e !he s!a!e b# s&a in" !he i(on and3or !ex! ea(h !i$e !he s!a!e (han"es be!&een on and o++. To $a,e a sin"le i!e$ (he(,able% use !he se!0he(,able)* $e!hod% li,e soK $enu.add)<% 4IBRATEZSETTINGZID% <% N4ibra!eN* .se!0he(,able)!rue*J This &ill dis la# a (he(,box &i!h !he $enu i!e$ )unless i!Ms in !he I(on Menu*. When !he i!e$ is sele(!ed% !he onO !ionsI!e$Sele(!ed)* (allba(, is (alled as usual. I! is here !ha! #ou $us! se! !he s!a!e o+ !he (he(,box. Oou (an Euer# !he (urren! s!a!e o+ !he i!e$ &i!h is0he(,ed)* and se! !he (he(,ed s!a!e &i!h se!0he(,ed)*. >ereMs &ha! !his loo,s li,e inside !he onO !ionsI!e$Sele(!ed)* (allba(,K s&i!(h )i!e$."e!I!e$Id)** T (ase 4IBRATEZSETTINGZIDK i+ )i!e$.is0he(,ed)** i!e$.se!0he(,ed)+alse*J else i!e$.se!0he(,ed)!rue*J re!urn !rueJ ... W To $a,e a "rou o+ $u!uall# ex(lusi'e radio bu!!on i!e$s% si$ l# assi"n !he sa$e "rou ID !o ea(h $enu i!e$ and (all se!Grou 0he(,able)*. In !his (ase% #ou donM!
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e @=
need !o (all se!0he(,able)* on ea(h $enu i!e$s% be(ause !he "rou as a &hole is se! (he(,able. >ereMs an exa$ le o+ !&o $u!uall# ex(lusi'e o !ions in a Sub$enuK SubMenu subMenu Y $enu.addSubMenu)N0olorN*J subMenu.add)0OLORZMENUZGROUP% 0OLORZREDZID% <% NRedN*J subMenu.add)0OLORZMENUZGROUP% 0OLORZBLUEZID% <% NBlueN*J subMenu.se!Grou 0he(,able)0OLORZMENUZGROUP% !rue% !rue*J In !he se!Grou 0he(,able)* $e!hod% !he +irs! ar"u$en! is !he "rou ID !ha! &e &an! !o se! (he(,able. The se(ond ar"u$en! is &he!her &e &an! !he "rou i!e$s !o be (he(,able. The las! one is &he!her &e &an! ea(h i!e$ !o be ex(lusi'el# (he(,able )i+ &e se! !his +alse% !hen all !he i!e$s &ill be (he(,boxes ins!ead o+ radio bu!!ons*. When !he "rou is se! !o be ex(lusi'e )radio bu!!ons*% ea(h !i$e a ne& i!e$ is sele(!ed% all o!her are au!o$a!i(all# de1sele(!ed. Shor!(u! ,e#s Dui(, a((ess shor!(u! ,e#s usin" le!!ers and3or nu$bers (an be added !o $enu i!e$s &i!h se!Al habe!i(Shor!(u!)(har* )!o se! (har shor!(u!*% se!Nu$eri(Shor!(u!)in!* )!o se! nu$eri( shor!(u!*% or se!Shor!(u!)(har%in!* )!o se! bo!h*. 0ase is no! sensi!i'e. For exa$ leK $enu.add)<% MENUZDUIT% <% NDui!N* .se!Al habe!i(Shor!(u!)MEM*J No&% &hen !he $enu is o en )or &hile holdin" !he MENU ,e#*% ressin" !he NEN ,e# &ill sele(! !his i!e$. This shor!(u! ,e# &ill be dis la#ed as a !i in !he $enu i!e$% belo& !he $enu i!e$ na$e )ex(e ! +or i!e$s in !he I(on Menu*. No!eK Shor!(u!s (anno! be added !o i!e$s in a 0on!ex! Menu enus .0ample :5
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e @?
Options enuActivity%java a(,a"e (o$.$enuJ i$ i$ i$ i$ i$ i$ i$ or! android.a .A(!i'i!#J or! android.(on!en!.In!en!J or! android.os.BundleJ or! android.'ie&.MenuJ or! android.'ie&.MenuI!e$J or! android.'ie&.SubMenuJ or! android.&id"e!.Toas!J
ubli( (lass O !ionsMenuA(!i'i!# ex!ends A(!i'i!# T VO'erride ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T su er.on0rea!e)sa'edIns!an(eS!a!e*J se!0on!en!4ie&)R.la#ou!.$ain*J
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e @9
W VO'erride ubli( boolean on0rea!eO !ionsMenu)Menu $enu* T $enu.add)NSe!!in"sN*.se!Al habe!i(Shor!(u!)MSM*J $enu.add)NDial adN*J SubMenu s$/ Y $enu.addSubMenu)NFileN*J s$/.add)No enN*J s$/.add)Nne&N*J s$/.add)N(loseN*J s$/.add)Nsa'eN*J s$/.add)Nsa'eAsN*J s$/.add)Nexi!N*J SubMenu s$8 Y $enu.addSubMenu)NEdi!N*J s$8.add)N0o #N*J s$8.add)N0u!N*J s$8.add)NPas!eN*J s$8.add)NUndoN*J $enu.add)NGa$esN*J $enu.add)NPro+ilesN*J $enu.add)NGaller#N*.se!I(on)R.dra&able.i(on*J re!urn !rueJ W VO'erride ubli( boolean onO !ionsI!e$Sele(!ed)MenuI!e$ i!e$* T i+)i!e$."e!Ti!le)*YY NFileN*T Toas!.$a,eTex!)"e!A li(a!ion0on!ex!)*% NFile Sele(!edN% Toas!.LENGT>ZLONG*.sho&)*J W else i+)i!e$."e!Ti!le)*YY NGa$esN*T Toas!.$a,eTex!)"e!A li(a!ion0on!ex!)*%
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e @;
NGa$es Sele(!edN% Toas!.LENGT>ZLONG*.sho&)*J W else i+)i!e$."e!Ti!le)*YY NDial adN*T In!en! inYne& In!en!)In!en!.A0TIONZDIAL*J s!ar!A(!i'i!#)in*J W else i+)i!e$."e!Ti!le)*YY NSe!!in"sN*T Toas!.$a,eTex!)"e!A li(a!ion0on!ex!)*% NSe!!in"s Sele(!edN% Toas!.LENGT>ZLONG*.sho&)*J W re!urn !rueJ W W enus from Cml optionsmenu%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: Q$enu x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN: Qi!e$ androidKidYNVLid3edi!IdN androidK!i!leYNEdi!N androidKi(onYNVdra&able3i(onN 3: Qi!e$ androidKidYNVLid3+ileIdN androidK!i!leYNFileN androidKi(onYNVdra&able3i(onN 3: Qi!e$ androidKidYNVLid3 as!eIdN androidK!i!leYNPas!eN androidKi(onYNVdra&able3i(onN 3: Q3$enu:
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e @B
menusfrom0ml%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: QLinearLa#ou! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKorien!a!ionYN'er!i(alN androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN+illZ aren!N: QTex!4ie& androidK!ex!YN0li(, Menu Bu!!onN androidKidYNVLid3Tex!4ie&</N androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N3: Q3LinearLa#ou!: Options enu3romCml%java a(,a"e (o$.$enuJ i$ i$ i$ i$ or! android.a .A(!i'i!#J or! android.os.BundleJ or! android.'ie&.MenuJ or! android.'ie&.MenuIn+la!erJ
ubli( (lass O !ionsMenuFro$C$l ex!ends A(!i'i!# T VO'erride ro!e(!ed 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T su er.on0rea!e)sa'edIns!an(eS!a!e*J se!0on!en!4ie&)R.la#ou!.$enus+ro$x$l*J W VO'erride ubli( boolean on0rea!eO !ionsMenu)Menu $enu* T MenuIn+la!er in+ Y ne& MenuIn+la!er)!his*J in+.in+la!e)R.$enu.o !ions$enu% $enu*J re!urn !rueJ W W
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e @A
-onte0t enu -onte0t enuActivity%java a(,a"e (o$.$enuJ i$ i$ i$ i$ i$ i$ i$ i$ i$ i$ or! android.a .A(!i'i!#J or! android.(on!en!.In!en!J or! android.os.BundleJ or! android.'ie&.0on!ex!MenuJ or! android.'ie&.MenuI!e$J or! android.'ie&.SubMenuJ or! android.'ie&.4ie&J or! android.'ie&.0on!ex!Menu.0on!ex!MenuIn+oJ or! android.&id"e!.Bu!!onJ or! android.&id"e!.Toas!J
ubli( (lass 0on!ex!MenuA(!i'i!# ex!ends A(!i'i!# T Bu!!on bu!!onJ VO'erride ro!e(!ed 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T su er.on0rea!e)sa'edIns!an(eS!a!e*J se!0on!en!4ie&)R.la#ou!.(on!ex!$enu*J bu!!onY)Bu!!on*+ind4ie&B#Id)R.id.(on!ex!Bu!!on*J re"is!erFor0on!ex!Menu)bu!!on*J W VO'erride ubli( 'oid on0rea!e0on!ex!Menu)0on!ex!Menu $enu% 4ie& '% 0on!ex!MenuIn+o $enuIn+o* T $enu.add)NSe!!in"sN*J $enu.add)NDial adN*J 33addin" sub$enus SubMenu s$/ Y $enu.addSubMenu)NFileN*J s$/.add)No enN*J s$/.add)Nne&N*J s$/.add)N(loseN*J
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e @@
s$/.add)Nsa'eN*J s$/.add)Nsa'eAsN*J $enu.add)NGa$esN*J $enu.add)NPro+ilesN*J W VO'erride ubli( boolean on0on!ex!I!e$Sele(!ed)MenuI!e$ i!e$* T i+)i!e$."e!Ti!le)*YY NFileN*T Toas!.$a,eTex!)"e!A li(a!ion0on!ex!)*%NFile Sele(!edN% Toas!.LENGT>ZLONG*.sho&)*J W else i+)i!e$."e!Ti!le)*YY NGa$esN*T Toas!.$a,eTex!)"e!A li(a!ion0on!ex!)*%NGa$es Sele(!edN% Toas!.LENGT>ZLONG*.sho&)*J W else i+)i!e$."e!Ti!le)*YY NDial adN*T In!en! inYne& In!en!)In!en!.A0TIONZDIAL*J s!ar!A(!i'i!#)in*J W re!urn !rueJ W W main%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: QLinearLa#ou! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N: QBu!!on androidK!ex!YNLon" PressN androidKidYNVLid3(on!ex!Bu!!onN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N3:
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /<<
Q3LinearLa#ou!: ,ypes 4esource Ea(h o+ !he do(u$en!s in !his se(!ion des(ribe !he usa"e% +or$a! and s#n!ax +or a (er!ain !# e o+ a li(a!ion resour(e !ha! #ou (an ro'ide in #our resour(es dire(!or# )res3*. >ereMs a brie+ su$$ar# o+ ea(h resour(e !# eK Ani$a!ion Resour(es De+ine re1de!er$ined ani$a!ions. T&een ani$a!ions are sa'ed in res3ani$3 and a((essed +ro$ !he R.ani$ (lass. Fra$e ani$a!ions are sa'ed in res3dra&able3 and a((essed +ro$ !he R.dra&able (lass. 0olor S!a!e Lis! Resour(e De+ine a (olor resour(es !ha! (han"es based on !he 4ie& s!a!e. Sa'ed in res3(olor3 and a((essed +ro$ !he R.(olor (lass. Dra&able Resour(es De+ine 'arious "ra hi(s &i!h bi!$a s or CML. Sa'ed in res3dra&able3 and a((essed +ro$ !he R.dra&able (lass. La#ou! Resour(e De+ine !he la#ou! +or #our a li(a!ion UI. Sa'ed in res3la#ou!3 and a((essed +ro$ !he R.la#ou! (lass. Menu Resour(e De+ine !he (on!en!s o+ #our a li(a!ion $enus. Sa'ed in res3$enu3 and a((essed +ro$ !he R.$enu (lass. S!rin" Resour(es De+ine s!rin"s% s!rin" arra#s% and lurals )and in(lude s!rin" +or$a!!in" and s!#lin"*. Sa'ed in res3'alues3 and a((essed +ro$ !he R.s!rin"% R.arra#% and R. lurals (lasses. S!#le Resour(e De+ine !he loo, and +or$a! +or UI ele$en!s. Sa'ed in res3'alues3 and a((essed +ro$ !he R.s!#le (lass. More Resour(e T# es De+ine 'alues su(h as booleans% in!e"ers% di$ensions% (olors% and o!her arra#s.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /</
Sa'ed in res3'alues3 bu! ea(h a((essed +ro$ uniEue R sub1(lasses )su(h as R.bool% R.in!e"er% R.di$en% e!(.*.
String 4esources A s!rin" resour(e ro'ides !ex! s!rin"s +or #our a li(a!ion &i!h o !ional !ex! s!#lin" and +or$a!!in". There are !hree !# es o+ resour(es !ha! (an ro'ide #our a li(a!ion &i!h s!rin"sK S!rin" CML resour(e !ha! ro'ides a sin"le s!rin". S!rin" Arra# CML resour(e !ha! ro'ides an arra# o+ s!rin"s. String A sin"le s!rin" !ha! (an be re+eren(ed +ro$ !he a +iles )su(h as an CML la#ou!*. li(a!ion or +ro$ o!her resour(e
*ote: A s!rin" is a si$ le resour(e !ha! is re+eren(ed usin" !he 'alue ro'ided in !he na$e a!!ribu!e )no! !he na$e o+ !he CML +ile*. So% #ou (an (o$bine s!rin" resour(es &i!h o!her si$ le resour(es in !he one CML +ile% under one Qresour(es: ele$en!. +ile lo(a!ionK res3'alues3filename.x$l The +ilena$e is arbi!rar#. The Qs!rin": ele$en!Ms na$e &ill be used as !he resour(e ID. (o$ iled resour(e da!a!# eK Resour(e oin!er !o a S!rin". resour(e re+eren(eK In Ga'aK R.s!rin".string_name In CMLKVs!rin"3string_name s#n!axK QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: Qresour(es: Qs!rin" na$eYNstring_nameN
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /<8
:text_stringQ3s!rin": Q3resour(es: ele$en!sK Qresour(es: 4eFuired% This $us! be !he roo! node. No a!!ribu!es. Qs!rin": A s!rin"% &hi(h (an in(lude s!#lin" !a"s. Be&are !ha! #ou $us! es(a e a os!ro hes and Euo!a!ion $ar,s. a!!ribu!esK na$e String. A na$e +or !he s!rin". This na$e &ill be used as !he resour(e ID. exa$ leK CML +ile sa'ed a! res3'alues3s!rin"s.x$lK QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: Qresour(es: Qs!rin" na$eYNhelloN:>ello[Q3s!rin": Q3resour(es: This la#ou! CML a lies a s!rin" !o a 4ie&K
QTex!4ie& androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N android:te0tGHIstring:)elloH 3: This a li(a!ion (ode re!rie'es a s!rin"K
S!rin" s!rin" Y "e!S!rin")R.s!rin".hello*J Oou (an use ei!her "e!S!rin")in!* or "e!Tex!)in!* !o re!ie'e a s!rin". "e!Tex!)in!* &ill re!ain an# ri(h !ex! s!#lin" a lied !o !he s!rin". String Array An arra# o+ s!rin"s !ha! (an be re+eren(ed +ro$ !he a li(a!ion.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /<=
*ote: A s!rin" arra# is a si$ le resour(e !ha! is re+eren(ed usin" !he 'alue ro'ided in !he na$e a!!ribu!e )no! !he na$e o+ !he CML +ile*. As su(h% #ou (an (o$bine s!rin" arra# resour(es &i!h o!her si$ le resour(es in !he one CML +ile% under one Qresour(es: ele$en!. +ile lo(a!ionK res3'alues3filename.x$l The +ilena$e is arbi!rar#. The Qs!rin"1arra#: ele$en!Ms na$e &ill be used as !he resour(e ID. (o$ iled resour(e da!a!# eK Resour(e oin!er !o an arra# o+ S!rin"s. resour(e re+eren(eK In Ga'aK R.arra#.string_array_name s#n!axK QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: Qresour(es: Qs!rin"1arra# na$eYNstring_array_nameN: Qi!e$ :text_stringQ3i!e$: Q3s!rin"1arra#: Q3resour(es: ele$en!sK Qresour(es: 4eFuired% This $us! be !he roo! node. No a!!ribu!es. Qs!rin"1arra#: De+ines an arra# o+ s!rin"s. 0on!ains one or $ore Qi!e$: ele$en!s. a!!ribu!esK na$e String. A na$e +or !he arra#. This na$e &ill be used as !he resour(e ID !o re+eren(e !he arra#. Qi!e$: A s!rin"% &hi(h (an in(lude s!#lin" !a"s. The 'alue (an be a re+eren(ed !o ano!her s!rin" resour(e. Mus! be a (hild o+ a Qs!rin"1arra#: ele$en!. Be&are !ha! #ou $us! es(a e a os!ro hes and Euo!a!ion $ar,s.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /<?
exa$ leK CML +ile sa'ed a! res3'alues3s!rin"s.x$lK QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: Qresour(es: Qs!rin"1arra# na$eYN&ee,N: Qi!e$:Sunda#Q3i!e$: Qi!e$:Monda#Q3i!e$: Qi!e$:Tuesda#Q3i!e$: Qi!e$:Wednesda#Q3i!e$: Qi!e$:Thursda#Q3i!e$: Qi!e$:Frida#da#Q3i!e$: Qi!e$:Sa!urda#Q3i!e$: Q3s!rin"1arra#: Q3resour(es: This a li(a!ion (ode re!rie'es a s!rin" arra#K
Resour(es res Y "e!Resour(es)*J S!rin"]^ &ee,Da#s Y res."e!S!rin"Arra#)R.arra#.&ee,*J Styling wit) +, # mar6up Oou (an add s!#lin" !o #our s!rin"s &i!h >TML $ar,u . For exa$ leK QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: Qresour(es: Qs!rin" na$eYN&el(o$eN:Wel(o$e !o Qb:AndroidQ3b:[Q3s!rin": Q3resour(es: Su
or!ed >TML ele$en!s in(ludeK Qb: +or bold !ex!. Qi: +or italic !ex!. Qu: +or underline !ex!.
So$e!i$es #ou $a# &an! !o (rea!e a s!#led !ex! resour(e !ha! is also used as a +or$a! s!rin". Nor$all#% !his &onM! &or, be(ause !he S!rin".+or$a!)S!rin"% ObHe(!...* $e!hod &ill s!ri all !he s!#le in+or$a!ion +ro$ !he s!rin". The &or,1 around !o !his is !o &ri!e !he >TML !a"s &i!h es(a ed en!i!ies% &hi(h are !hen re(o'ered &i!h +ro$>!$l)S!rin"*% a+!er !he +or$a!!in" !a,es la(e. For exa$ leK
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /<9
/. S!ore #our s!#led !ex! resour(e as an >TML1es(a ed s!rin"K Qresour(es: Qs!rin" na$eYN&el(o$eZ$essa"esN:>ello% _/`s[ Oou ha'e al!Jb:_8`d ne& $essa"esal!J3b:.Q3s!rin": Q3resour(es: In !his +or$a!!ed s!rin"% a Qb: ele$en! is added. No!i(e !ha! !he o enin" bra(,e! is >TML1es(a ed% usin" !he al!J no!a!ion.
8. Then +or$a! !he s!rin" as usual% bu! also (all +ro$>!$l)S!rin"* !o (on'er!
Resour(es res Y "e!Resour(es)*J S!rin" !ex! Y S!rin".+or$a!)res."e!S!rin")R.s!rin".&el(o$eZ$essa"es*% userna$e% $ail0oun!*J 0harSeEuen(e s!#ledTex! Y >!$l.+ro$>!$l)!ex!*J Be(ause !he +ro$>!$l)S!rin"* $e!hod &ill +or$a! all >TML en!i!ies% be sure !o es(a e an# ossible >TML (hara(!ers in !he s!rin"s #ou use &i!h !he +or$a!!ed !ex!% usin" h!$lEn(ode)S!rin"*. For ins!an(e% i+ #ouMll be assin" a s!rin" ar"u$en! !o S!rin".+or$a!)* !ha! $a# (on!ain (hara(!ers su(h as NQN or NaN% !hen !he# $us! be es(a ed be+ore +or$a!!in"% so !ha! &hen !he +or$a!!ed s!rin" is assed !hrou"h +ro$>!$l)S!rin"*% !he (hara(!ers (o$e ou! !he &a# !he# &ere ori"inall# &ri!!en. For exa$ leK S!rin" es(a edUserna$e Y Tex!U!il.h!$lEn(ode)userna$e*J Resour(es res Y "e!Resour(es)*J S!rin" !ex! Y S!rin".+or$a!)res."e!S!rin")R.s!rin".&el(o$eZ$essa"es*% es(a edUserna$e% $ail0oun!*J 0harSeEuen(e s!#ledTex! Y >!$l.+ro$>!$l)!ex!*J
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /<;
9ser Interface -omponents Different -omponents of 9ser Interfaces% The basi( (o$ onen!s. A(!i'i!# )S(reen* 4ie&s )4ie&Grou * or 0on!rols or Wid"e!s La#ou!s A(!i'i!#K 1 A(!i'i!ies re resen!s !he s(reen !ha! is bein" dis la#ed. Assi"nin" a 'ie& !o !he A(!i'i!# &ill dis la#s !he User In!er+a(es. 4ie&sK 1 All !he User in!er+a(es are di'ided +ro$ 'ie&s. 4ie&s are !he base (lasses +or all UI ele$en!s. 4ie&Grou sK 1 Mul!i le 'ie&s (an be (o$bined !o"e!her in!o 4ie&Grou s. 4ie&Grou s are used !o $ana"e !he la#ou! o+ (hild 'ie&s. 4ie&s are !&o !# es. /. Passin" a 'ie& ins!an(e !o !he se!0on!en!4ie&) * $e!hod in !he A(!i'i!#. 8. Passin" a la#ou! resour(e id !o !he se!0on!en!4ie&) * $e!hod &i!h !he +ind4ie&B#Id) * $e!hod. Se(ond $e!hod is bes! +or (rea!in" UI. Be(ause b# $en!ionin" !he la#ou! resour(e id se ara!es !he resen!a!ion la#er +ro$ !he a li(a!ion lo"i(. 0ode redu(in" &ill be "rea! le'el. Reusabili!# o+ !he (ode.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /<B
Di++eren! la#ou!s (an be $ade +i! !o di++eren! $obile de'i(es o+ 'arious (on+i"ura!ions. No!eK 1 or!rai! $ode3 lands(a e $ode
#ayouts La#ou!s are used !o osi!ion% !he (on!rol o+ !he user in!er+a(es. La#ou!s are de+ined !he osi!ion o+ !he (hild 'ie&s and !he la#ou! s!ru(!ure. 4ie&Grou (lass ser'es as !he base (lass +or !he la#ou!s )android.!ex!.La#ou!*. /. 3rame#ayoutK 1 A Fra$eLa#ou! add !he (on!rols !o !he To le+! (orner o+ !he s(reen. E'er# ne& (on!rol !o be added !he s!a(, &i!h ea(h ne& 'ie& o((u #in" !he old 'ie&. I+ &e add ne& ele$en! !hen old &ill "o !o ba(,"round and ne& &ill 'isible. 8. #eanier#ayoutK1 I! ali"ns !he (o$ onen!s ei!her 'er!i(al or hori6on!al line. A 'er!i(al la#ou! &ill be ha'in" a column o+ 'ie&s. A hori6on!al la#ou! &ill be ha'in" a row o+ 'ie&s. =. 4elative#ayoutK 1 I! de+ines !he osi!ions o+ ea(h (hild 'ie& rela!i'e !o !he o!her (o$ onen!s and s(reen boundaries. ?. ,able#ayoutK 1 A TableLa#ou! allo&s dis la#in" !he (o$ onen!s in!o ro&s and (olu$ns. Table ro& obHe(!s &ill be resen! in side !able la#ou! ele$en!. Ea(h !able ro& obHe(!s de+ines a sin"le ro& in !he !able. Ea(h ro& as < or $ore (ells. Ea(h (ell &ill be holdin" a sin"le 'ie& obHe(!. The !able &ill be ha'in" as $an# (ells as !he ro& &i!h !he $os! nu$ber o+ (ells. The &id!h o+ a (olu$n is de+ined b# !he ro& &i!h !he &id"e! (ell in !ha! (olu$n.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /<A
A TableLa#ou! (an s e(i+# a (olu$n as shrin,able b# (allin" se!0olu$nShrin,able) * $e!hod. I+ !his is $ar,ed as shrin,able !he (olu$n &id!h (an be redu(ed !o +i! !he !able in !o i!s aren! obHe(!. A (olu$n (an be need s!re!(hin" b# (allin" se!0olu$nS!re(habel) * $e!hod. A (olu$n (an be hided b# (allin" se!0olu$n0olla sed) * $e!hod. 0ells should be added !o a ro& in in(reasin" (olu$n order% (olu$n nu$bers are index based )<*. I+ a (olu$n nu$ber is no! s e(i+ied i! &ill au!o$a!i(all# in(reased !o !he nex! a'ailable (olu$n. I+ a (olu$n nu$ber is s,i ed i! &ill be (onsidered as e$ !# (ell in !ha! ro&. An Android la#ou! is a (lass !ha! handles arran"in" !he &a# i!s (hildren a ear on !he s(reen. An#!hin" !ha! is a 4ie& )or inheri!s +ro$ 4ie&* (an be a (hild o+ a la#ou!. All o+ !he la#ou!s inheri! +ro$ 4ie& Grou )&hi(h inheri!s +ro$ 4ie&* so #ou (an nes! la#ou!s. Oou (ould also (rea!e #our o&n (us!o$ la#ou! b# $a,in" a (lass !ha! inheri!s +ro$ 4ie& Grou . The s!andard La#ou!s areK Absolute #ayout 3rame #ayout #inear #ayout 4elative #ayout Table La#ou! '% Absolute #ayout: Absolu!e La#ou! is based on !he si$ le idea o+ la(in" ea(h (on!rol a! an absolu!e osi!ion. Oou s e(i+# !he exa(! x and # (oordina!es on !he s(reen +or ea(h (on!rol. This is no! re(o$$ended +or $os! UI de'elo $en! )in +a(! Absolu!e La#ou! is (urren!l# de re(a!ed* sin(e absolu!el# osi!ionin" e'er# ele$en! on !he s(reen $a,es an in+lexible UI !ha! is $u(h $ore di++i(ul! !o $ain!ain. 0onsider &ha! ha ens i+ a (on!rol needs !o be added !o !he UI. Oou &ould ha'e !o (han"e !he osi!ion o+ e'er# sin"le ele$en! !ha! is shi+!ed b# !he ne& (on!rol. >ere is a sa$ le La#ou! CML usin" Absolu!e La#ou!.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /<@
JAbsolute#ayout x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN+illZ aren!NA J;utton androidKidYNVLid3ba(,bu!!onN androidK!ex!YNBa(,N androidKla#ou!ZxYN/< xN androidKla#ou!Z#YN9 xN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J,e0tView androidKla#ou!ZxYN/< xN androidKla#ou!Z#YN//< xN androidK!ex!YNFirs! Na$eN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J.dit,e0t androidKla#ou!ZxYN/9< xN androidKla#ou!Z#YN/<< xN androidK&id!hYN/<< xN androidKla#ou!Z&id!hYN&ra (on!en!N androidKla#ou!Zhei"h!YN&ra (on!en!N :A J,e0tView androidKla#ou!ZxYN/< xN androidKla#ou!Z#YN/;< xN androidK!ex!YNLas! Na$eN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J.dit,e0t androidKla#ou!ZxYN/9< xN androidKla#ou!Z#YN/9< xN androidK&id!hYN/<< xN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J:Absolute#ayoutA No!e ho& ea(h ele$en! has androidKla#ou!Zx and androidKla#ou!Z# s e(i+ied. Android de+ines !he !o le+! o+ !he s(reen as )<%<* so !he la#ou!Zx 'alue &ill $o'e !he (on!rol !o !he ri"h!% and !he la#ou!Z# 'alue &ill $o'e !he (on!rol do&n. >ere is a s(reensho! o+ !he la#ou! rodu(ed b# !his CML.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e //<
@% 3rame#ayout Fra$eLa#ou! is desi"ned !o dis la# a sin"le i!e$ a! a !i$e. Oou (an ha'e $ul!i le ele$en!s &i!hin a Fra$eLa#ou! bu! ea(h ele$en! &ill be osi!ioned based on !he !o le+! o+ !he s(reen. Ele$en!s !ha! o'erla &ill be dis la#ed o'erla in". I ha'e (rea!ed a si$ le CML la#ou! usin" Fra$eLa#ou! !ha! sho&s ho& !his &or,s. J3rame#ayout androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN+illZ aren!N x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidNA JImageView androidKsr(YNVdra&able3i(onN androidKs(aleT# eYN+i!0en!erN androidKla#ou!Zhei"h!YN+illZ aren!N androidKla#ou!Z&id!hYN+illZ aren!N:A J,e0tView androidK!ex!YNLearn1Android.(o$N androidK!ex!Si6eYN8?s N androidK!ex!0olorYN2<<<<<<N androidKla#ou!Zhei"h!YN+illZ aren!N androidKla#ou!Z&id!hYN+illZ aren!N androidK"ra'i!#YN(en!erN:A J:3rame#ayoutA
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e ///
Oou (an see I had bo!h !he I$a"e4ie& and Tex!4ie& +ill !he aren! in bo!h hori6on!al and 'er!i(al la#ou!. Gra'i!# s e(i+ies &here !he !ex! a ears &i!hin i!s (on!ainer% so I se! !ha! !o (en!er. I+ I had no! se! a "ra'i!# !hen !he !ex! &ould ha'e a eared a! !he !o le+! o+ !he s(reen. Fra$eLa#ou! (an be(o$e $ore use+ul &hen ele$en!s are hidden and dis la#ed ro"ra$$a!i(all#. Oou (an use !he a!!ribu!e androidK'isibili!# in !he CML !o hide s e(i+i( ele$en!s. Oou (an (all se!4isibili!# +ro$ !he (ode !o a((o$ lish !he sa$e !hin". The !hree a'ailable 'isibili!# 'alues are 'isible% in'isible )does no! dis la#% bu! s!ill !a,es u s a(e in !he la#ou!*% and "one )does no! dis la#% and does no! !a,e s a(e in !he la#ou!*. ?%#inear#ayout: LinearLa#ou! or"ani6es ele$en!s alon" a sin"le line. Oou s e(i+# &he!her !ha! line is 'er!i(al or hori6on!al usin" androidKorien!a!ion. >ere is a sa$ le La#ou! CML usin" LinearLa#ou!. J#inear#ayout x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKorien!a!ionYNhori6on!alN androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN+illZ aren!NA J;utton androidKidYNVLid3ba(,bu!!onN androidK!ex!YNBa(,N androidKla#ou!Z&id!hYN&ra Z(on!en!N
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e //8
androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J,e0tView androidK!ex!YNFirs! Na$eN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J.dit,e0t androidK&id!hYN/<< xN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J,e0tView androidK!ex!YNLas! Na$eN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J.dit,e0t androidK&id!hYN/<< xN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J:#inear#ayoutA >ere is a s(reensho! o+ !he resul! o+ !he abo'e CML.
>ere is a s(reensho! o+ !he sa$e CML ex(e ! !ha! !he androidKorien!a!ion has been (han"ed !o hori6on!al.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e //=
Oou $i"h! no!e !ha! !he Edi!Tex! +ield a! !he end o+ !he line has had i!s &id!h redu(ed in order !o +i!. Android &ill !r# !o $a,e adHus!$en!s &hen ne(essar# !o +i! i!e$s on s(reen. The las! a"e o+ !his !u!orial &ill (o'er one $e!hod !o hel deal &i!h !his. I $en!ioned on !he +irs! a"e !ha! La#ou!s (an be nes!ed. LinearLa#ou! is +reEuen!l# nes!ed% &i!h hori6on!al and 'er!i(al la#ou!s $ixed. >ere is an exa$ le o+ !his. J#inear#ayout x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKorien!a!ionYN'er!i(alN androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN+illZ aren!NA J;utton androidKidYNVLid3ba(,bu!!onN androidK!ex!YNBa(,N androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J#inear#ayout androidKorien!a!ionYNhori6on!alN androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN&ra Z(on!en!NA J,e0tView
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e //?
androidK!ex!YNFirs! Na$eN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J.dit,e0t androidK&id!hYN/<< xN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J:#inear#ayoutA J#inear#ayout androidKorien!a!ionYNhori6on!alN androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN&ra Z(on!en!NA J,e0tView androidK!ex!YNLas! Na$eN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J.dit,e0t androidK&id!hYN/<< xN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J:#inear#ayoutA J:#inear#ayoutA As #ou (an see &e ha'e a 4er!i(al LinearLa#ou! &hose (hildren are a bu!!on% and !&o hori6on!al LinearLa#ou!s. Ea(h hori6on!al LinearLa#ou! has !&o (hild (on!rols. Oou should no!e !ha! in !he (hild LinearLa#ou! ele$en!s I used androidKla#ou!Zhei"h!YS&ra Z(on!en!S ins!ead o+ +illZ aren!. I+ I had used +illZ aren! !he +irs! na$e Tex!4ie& and Edi!4ie& &ould ha'e !a,en all o+ !he a'ailable s a(e on !he s(reen% and !he Las! Na$e &ould no! ha'e been dis la#ed. >ere is &ha! !his CML does dis la#.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e //9
Nes!ed La#ou!s do no! ha'e !o be o+ one !# e. I (ould% +or exa$ le% ha'e a LinearLa#ou! as one o+ !he (hildren in a Fra$eLa#ou!.
$%4elative#ayout: Rela!i'eLa#ou! la#s ou! ele$en!s based on !heir rela!ionshi s &i!h one ano!her% and &i!h !he aren! (on!ainer. This is ar"uabl# !he $os! (o$ li(a!ed la#ou!% and &e need se'eral ro er!ies !o a(!uall# "e! !he la#ou! &e &an!. 4elative ,o -ontainer : These ro er!ies &ill la#ou! ele$en!s rela!i'e !o !he aren! (on!ainer.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e //;
androidKla#ou!Zali"nParen!Bo!!o$ I Pla(es !he bo!!o$ o+ !he ele$en! on !he bo!!o$ o+ !he (on!ainer androidKla#ou!Zali"nParen!Le+! I Pla(es !he le+! o+ !he ele$en! on !he le+! side o+ !he (on!ainer androidKla#ou!Zali"nParen!Ri"h! I Pla(es !he ri"h! o+ !he ele$en! on !he ri"h! side o+ !he (on!ainer androidKla#ou!Zali"nParen!To I Pla(es !he ele$en! a! !he !o o+ !he (on!ainer androidKla#ou!Z(en!er>ori6on!al I 0en!ers !he ele$en! hori6on!all# &i!hin i!s aren! (on!ainer androidKla#ou!Z(en!erInParen! I 0en!ers !he ele$en! bo!h hori6on!all# and 'er!i(all# &i!hin i!s (on!ainer androidKla#ou!Z(en!er4er!i(al I 0en!ers !he ele$en! 'er!i(all# &i!hin i!s aren! (on!ainer
4elative ,o Ot)er .lements : These ro er!ies allo& #ou !o la#ou! ele$en!s rela!i'e !o o!her ele$en!s on s(reen. The 'alue +or ea(h o+ !hese ele$en!s is !he id o+ !he ele$en! #ou are usin" !o la#ou! !he ne& ele$en!. Ea(h ele$en! !ha! is used in !his &a# $us! ha'e an ID de+ined usin" androidKidYSVLid3CCCCCS &here CCCCC is re la(ed &i!h !he desired id. Oou use RVid3CCCCCS !o re+eren(e an ele$en! b# i!s id. One !hin" !o re$e$ber is !ha! re+eren(in" an ele$en! be+ore i! has been de(lared &ill rodu(e an error.
androidKla#ou!Zabo'e I Pla(es !he ele$en! abo'e !he s e(i+ied ele$en! androidKla#ou!Zbelo& I Pla(es !he ele$en! belo& !he s e(i+ied ele$en! androidKla#ou!Z!oLe+!O+ I Pla(es !he ele$en! !o !he le+! o+ !he s e(i+ied ele$en! androidKla#ou!Z!oRi"h!O+ I Pla(es !he ele$en! !o !he ri"h! o+ !he s e(i+ied ele$en!
Alignment 1it) Ot)er .lements : These ro er!ies allo& #ou !o s e(i+# ho& ele$en!s are ali"ned in rela!ion !o o!her ele$en!s.
androidKla#ou!Zali"nBaseline I Ali"ns baseline o+ !he ne& ele$en! &i!h !he baseline o+ !he s e(i+ied ele$en!
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e //B
androidKla#ou!Zali"nBo!!o$ I Ali"ns !he bo!!o$ o+ ne& ele$en! in &i!h !he bo!!o$ o+ !he s e(i+ied ele$en! androidKla#ou!Zali"nLe+! I Ali"ns le+! ed"e o+ !he ne& ele$en! &i!h !he le+! ed"e o+ !he s e(i+ied ele$en! androidKla#ou!Zali"nRi"h! I Ali"ns ri"h! ed"e o+ !he ne& ele$en! &i!h !he ri"h! ed"e o+ !he s e(i+ied ele$en! androidKla#ou!Zali"nTo I Pla(es !o o+ !he ne& ele$en! in ali"n$en! &i!h !he !o o+ !he s e(i+ied ele$en!
>ere is a sa$ le CML La#ou! J4elative#ayout androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN+illZ aren!N x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidNA J;utton androidKidYNVLid3ba(,bu!!onN androidK!ex!YNBa(,N androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J,e0tView androidKidYNVLid3+irs!Na$eN androidK!ex!YNFirs! Na$eN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidKla#ou!Zbelo&YNVid3ba(,bu!!onN :A J.dit,e0t androidK&id!hYN/<< xN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidKla#ou!Z!oRi"h!O+YNVid3+irs!Na$eN androidKla#ou!Zali"nBaselineYNVid3+irs!Na$eN :A J,e0tView androidKidYNVLid3las!Na$eN androidK!ex!YNLas! Na$eN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidKla#ou!Zbelo&YNVid3+irs!Na$eN :A J.dit,e0t androidK&id!hYN/<< xN
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e //A
androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidKla#ou!Z!oRi"h!O+YNVid3las!Na$eN androidKla#ou!Zali"nBaselineYNVid3las!Na$eN :A J:4elative#ayoutA >ere is !he s(reen rodu(ed b# !ha! CML.
I &an!ed !o sho& !his !o #ou be(ause !he +irs! !i$e I $ade a Rela!i'eLa#ou! I did exa(!l# !his and !hen loo,ed a! !he s(reen and said% R>an" on a $inu!e% !ha!-s no! &ha! I &an!ed[S The roble$ here is !ha! &hen Android dra&s !he Tex!4ie& las! Na$e belo& !he Tex!4ie& +irs! Na$e i! onl# se!s aside !he s a(e i! needs +or !he Tex!4ie&. Android onl# reads !he La#ou! CML one !i$e so i! doesn-! ,no& !ha! an Edi!4ie& is !he nex! i!e$ and doesn-! lan +or i!. So &hen !he Edi!4ie& is dra&n !o !he ri"h! o+ !he Tex!4ie& i! onl# has !he hei"h! o+ !he Tex!4ie& !o &or, &i!h so i! o'erla s !he Edi!4ie& abo'e i!. >ere is !he La#ou! CML I &ro!e !o (rea!e !he +or$ !he &a# i! should loo,.
androidKidYNVLid3ba(,bu!!onN androidK!ex!YNBa(,N androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J,e0tView androidKidYNVLid3+irs!Na$eN androidK!ex!YNFirs! Na$eN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidKla#ou!Zbelo&YNVid3ba(,bu!!onN :A J.dit,e0t androidKidYNVLid3edi!Firs!Na$eN androidK&id!hYN/<< xN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidKla#ou!Z!oRi"h!O+YNVid3+irs!Na$eN androidKla#ou!Zbelo&YNVid3ba(,bu!!onN:A J.dit,e0t androidKidYNVLid3edi!Las!Na$eN androidK&id!hYN/<< xN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidKla#ou!Zbelo&YNVid3edi!Firs!Na$eN androidKla#ou!Zali"nLe+!YNVid3edi!Firs!Na$eN:A J,e0tView androidKidYNVLid3las!Na$eN androidK!ex!YNLas! Na$eN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidKla#ou!Z!oLe+!O+YNVid3edi!Las!Na$eN androidKla#ou!Zbelo&YNVid3edi!Firs!Na$eN :A
J:4elative#ayoutA Oou robabl# no!i(ed !ha! I had !o rearran"e !he ele$en!s in !he CML sin(e% as I alread# $en!ioned% #ou (anno! re+eren(e an ele$en! !ha! has no! alread# been laid ou!. >ere is &ha! !he u da!ed Rela!i'eLa#ou! rodu(es.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /8<
B% ,able#ayout : Table La#ou! or"ani6es (on!en! in!o ro&s and (olu$ns. The ro&s are de+ined in !he la#ou! CML% and !he (olu$ns are de!er$ined au!o$a!i(all# b# Android. This is done b# (rea!in" a! leas! one (olu$n +or ea(h ele$en!. So% +or exa$ le% i+ #ou had a ro& &i!h !&o ele$en!s and a ro& &i!h +i'e ele$en!s !hen #ou &ould ha'e a la#ou! &i!h !&o ro&s and +i'e (olu$ns. Oou (an s e(i+# !ha! an ele$en! should o((u # $ore !han one (olu$n usin" androidKla#ou!Zs an. This (an in(rease !he !o!al (olu$n (oun! as &ell% so i+ &e ha'e a ro& &i!h !&o ele$en!s and ea(h ele$en! has androidKla#ou!Zs anYS=b !hen #ou &ill ha'e a! leas! six (olu$ns in #our !able. B# de+aul!% Android la(es ea(h ele$en! in !he +irs! unused (olu$n in !he ro&. Oou (an% ho&e'er% s e(i+# !he (olu$n an ele$en! should o((u # usin" androidKla#ou!Z(olu$n. >ere is so$e sa$ le CML usin" Table La#ou!. J,able#ayout androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN+illZ aren!N x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidNA J,able4owA J;utton androidKidYNVLid3ba(,bu!!onN androidK!ex!YNBa(,N
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /8/
androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J:,able4owA J,able4owA J,e0tView androidK!ex!YNFirs! Na$eN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidKla#ou!Z(olu$nYN/N :A J.dit,e0t androidK&id!hYN/<< xN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J:,able4owA J,able4owA J,e0tView androidK!ex!YNLas! Na$eN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidKla#ou!Z(olu$nYN/N :A J.dit,e0t androidK&id!hYN/<< xN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J:,able4owA J:,able#ayoutA This is !he resul! o+ !ha! CML.
K% Alternate#ayout : On !he LinearLa#ou! a"e I $en!ioned !ha! Android &ill shrin, ele$en!s &hen !he# don-! all +i! on !he s(reen. Oou (an redu(e !he need +or !his b# usin" al!erna!e la#ou!s +or di++eren! s(reen orien!a!ions. So% +or exa$ le% #ou ha'e a LinearLa#ou! !ha! loo,s re!!# "ood in Lands(a e bu! does
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /88
no! ha'e !he roo$ i! needs in Por!rai! $ode. Be+ore loo,in" in !he res3la#ou! +older +or #our la#ou! CML Android &ill (he(, +or one o+ !hese al!erna!e la#ou!s.
res3la#ou!1land I The al!erna!e la#ou! +or a lands(a e UI res3la#ou!1 or! I The al!erna!e la#ou! +or a or!rai! UI res3lauou!1sEuare I The al!erna!e la#ou! +or a sEuare UI
There are $an# Al!erna!e Resour(e !# es #ou (an use in addi!ion !o s(reen orien!a!ion. A $ore (o$ le!e lis! (an be +ound here. I a$ "oin" !o (rea!e a +older na$ed la#ou!1land under !he res +older and la(e !his CML under !he ne& +older. The CML +ile should ha'e !he sa$e na$e i! has in !he la#ou! +older% in $# (ase linearZla#ou!.x$l. J#inear#ayout x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKorien!a!ionYNhori6on!alN androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN+illZ aren!NA J;utton androidKidYNVLid3ba(,bu!!onN androidK!ex!YNBa(,N androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J,e0tView androidK!ex!YNFirs! Na$eN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J.dit,e0t androidK&id!hYN/<< xN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J,e0tView androidK!ex!YNLas! Na$eN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J.dit,e0t androidK&id!hYN/<< xN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N :A J:#inear#ayoutA
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /8=
In !he E$ula!or #ou (an ress B on #our nu$ber ad !o (han"e be!&een Lands(a e and Por!rai! orien!a!ions. When I s&i!(h !o lands(a e I see !he La#ou! +ro$ !he la#ou!1land +older.
Tha! &ra s u $# ar!i(le on !he s!andard la#ou!s !ha! (o$e &i!h Android. As al&a#s% lease lea'e (o$$en!s &i!h an# Eues!ions #ou ha'e on !he subHe(!% or an#!hin" #ou &ould li,e !o see elabora!ed on in a +u!ure ar!i(le. Than, #ou +or readin".
,elep)ony We are usin" $obiles +or $a,in" a (alls% s$s. I! is used !o (o$$uni(a!ion.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /8?
-ommunication is of two types% /. Ma,in" 0alls 8. Ma,in" Messa"es 0o$$uni(a!ion c 111111111111111111111111111111111111111111111111111111111111111111111111111111 c c 0alls Messa"in" c c 1111111111111111111 111111111111111111111111 c c c c In(o$in" Ou!"oin" Sendin" Re(ei'in" (alls (alls Messa"es Messa"es c 1111111111111111111111111 1Buildin" !he $essa"es Re(ei'in" !he1 c c 1Assi"nin" !he (on!a(! 1$essa"es)Por!* Moni!orin" Ini!iali6in" a (all 1Sendin" !he $essa"es The (alls $ana"in" a (all Incoming messages:5 Nor$al Messa"es Flash $essa"es )0all su$$ar#* SMS 11 : Tex! Messa"es MMS 11 : 4ideoa Audio Messa"es Re(ei'in" $essa"es b# usin" PORT. We (an $oni!or and i! sends !o inbo0% We are no! (han"e PORT nu$bers. 1ay of ma6ing t)e calls: 5 /. 0rea!in" #our In!en! 8. Quses1 er$ission: 'st way -reating your Intent
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /89
Intent myIntentYne& Intent )In!en!.A0TIONZDIAL% Uri. arseIn!)R@@9@9=A9;?S**J s!ar!A(!i'i!# )myIntent*J or s!ar!A(!i'i!#ForResul! )In!en! obH% ReEues! 0ode*J @nd way Quses1 er$ission na$eY Randroid. er$ission.0ALLZP>ONES: Tele hon# Mana"er &ill $ana"e all !hese a(!i'i!ies. Phones are 8 !# es. GSM)An#* 111 : Global S#s!e$ +or Mobile. 1111 IMEI 0DMA )S e(i+i(* 11111 :0ode Di'ision Mul!i le A((ess 1111 MEID IMEI 111 : In!erna!ional Mobile EEui $en! Iden!i!# MEID 111 : Mobile EEui $en! Iden!i+ier. ,elep)one anager S!a!e o+ !he Mobile Si$ (ard )subs(riber iden!i!# $odule* UniEueness +ea!ures )IMEI Nu$ber* De'i(es Phone !# e 0alls de ends on ne!&or, o era!or Da!a 111 :Da!a A(!i'i!# Da!a S!a!e "oints:5 ,elep)ony anager:5 The Tele hon#Mana"er ro'ides a((ess !o !he in+or$a!ion abou! !he Tele hon# ser'i(es on !he de'i(es. A li(a!ions &ill be usin" !he $e!hods in !he Tele hon#Mana"er (lass !o de!er$ine Tele hone s!a!e% ser'i(es% subs(riber in+or$a!ion. I! (onsis!s o+ !he android.!ele hon# and android.!ele hon#."s$ a(,a"es. A li(a!ions &ill be re"is!erin" a lis!ener !o re(ei'e no!i+i(a!ions o+ (han"es in !he !ele hone s!a!e. -onstants
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /8;
Broad(as! in!en! a(!ion indi(a!in" S!rin A0TIONZP>ONEZSTATEZ0>A !ha! !he (all s!a!e )(ellular* on !he " NGED de'i(e has (han"ed. in! 0ALLZSTATEZIDLE De'i(e (all s!a!eK No a(!i'i!#. in! 0ALLZSTATEZOFF>OO5 De'i(e (all s!a!eK O++1hoo,. in! 0ALLZSTATEZRINGING De'i(e (all s!a!eK Rin"in". Da!a (onne(!ion is a(!i'e% bu! in! DATAZA0TI4ITOZDORMANT h#si(al lin, is do&n Da!a (onne(!ion a(!i'i!#K 0urren!l# in! DATAZA0TI4ITOZIN re(ei'in" IP PPP !ra++i(. Da!a (onne(!ion a(!i'i!#K 0urren!l# in! DATAZA0TI4ITOZINOUT bo!h sendin" and re(ei'in" IP PPP !ra++i(. Da!a (onne(!ion a(!i'i!#K No in! DATAZA0TI4ITOZNONE !ra++i(. Da!a (onne(!ion a(!i'i!#K 0urren!l# in! DATAZA0TI4ITOZOUT sendin" IP PPP !ra++i(. in! DATAZ0ONNE0TED Da!a (onne(!ion s!a!eK 0onne(!ed. Da!a (onne(!ion s!a!eK 0urren!l# in! DATAZ0ONNE0TING se!!in" u a da!a (onne(!ion. Da!a (onne(!ion s!a!eK in! DATAZDIS0ONNE0TED Dis(onne(!ed. in! DATAZSUSPENDED Da!a (onne(!ion s!a!eK Sus ended. The loo,u ,e# used &i!h !he A0TIONZP>ONEZSTATEZ0>A S!rin ECTRAZIN0OMINGZNUMBER NGED broad(as! +or a S!rin" " (on!ainin" !he in(o$in" hone nu$ber. The loo,u ,e# used &i!h !he S!rin A0TIONZP>ONEZSTATEZ0>A ECTRAZSTATE " NGED broad(as! +or a S!rin" (on!ainin" !he ne& (all s!a!e. in! NETWOR5ZTOPEZ/xRTT 0urren! ne!&or, is /xRTT 0urren! ne!&or, is 0DMAK Ei!her in! NETWOR5ZTOPEZ0DMA IS@9A or IS@9B in! NETWOR5ZTOPEZEDGE 0urren! ne!&or, is EDGE in! NETWOR5ZTOPEZE>RPD 0urren! ne!&or, is e>RPD in! NETWOR5ZTOPEZE4DOZ< 0urren! ne!&or, is E4DO re'ision
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /8B
in! in! in! in! in! in! in! in! in! in! in! in! in! in! in! in! in! in! in! in!
< 0urren! ne!&or, is E4DO re'ision NETWOR5ZTOPEZE4DOZA A 0urren! ne!&or, is E4DO re'ision NETWOR5ZTOPEZE4DOZB B NETWOR5ZTOPEZGPRS 0urren! ne!&or, is GPRS NETWOR5ZTOPEZ>SDPA 0urren! ne!&or, is >SDPA NETWOR5ZTOPEZ>SPA 0urren! ne!&or, is >SPA NETWOR5ZTOPEZ>SUPA 0urren! ne!&or, is >SUPA NETWOR5ZTOPEZIDEN 0urren! ne!&or, is iDen NETWOR5ZTOPEZLTE 0urren! ne!&or, is LTE NETWOR5ZTOPEZUMTS 0urren! ne!&or, is UMTS NETWOR5ZTOPEZUN5NOWN Ne!&or, !# e is un,no&n P>ONEZTOPEZ0DMA Phone radio is 0DMA. P>ONEZTOPEZGSM Phone radio is GSM. P>ONEZTOPEZNONE No hone radio. P>ONEZTOPEZSIP Phone is 'ia SIP. SIM (ard s!a!eK no SIM (ard is SIMZSTATEZABSENT a'ailable in !he de'i(e SIMZSTATEZNETWOR5ZLO05 SIM (ard s!a!eK Lo(,edK reEuries a ED ne!&or, PIN !o unlo(, SIM (ard s!a!eK Lo(,edK reEuires SIMZSTATEZPINZREDUIRED !he userMs SIM PIN !o unlo(, SIM (ard s!a!eK Lo(,edK reEuires SIMZSTATEZPU5ZREDUIRED !he userMs SIM PU5 !o unlo(, SIMZSTATEZREADO SIM (ard s!a!eK Read# SIMZSTATEZUN5NOWN SIM (ard s!a!eK Un,no&n.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /8A
ubli( in! get-allState )* Re!urns a (ons!an! indi(a!in" !he (all s!a!e )(ellular* on !he de'i(e. ubli( 0ellLo(a!ion get-ell#ocation )* Re!urns !he (urren! lo(a!ion o+ !he de'i(e. Re!urn null i+ (urren! lo(a!ion is no! a'ailable. ReEuires er$issionK A00ESSZ0OARSEZLO0ATION or A00ESSZFINEZLO0ATI ON. ubli( in! getDataActivity )* Re!urns a (ons!an! indi(a!in" !he !# e o+ a(!i'i!# on a da!a (onne(!ion )(ellular*.
ubli( in! getDataState )* Re!urns a (ons!an! indi(a!in" !he (urren! da!a (onne(!ion s!a!e )(ellular*.
ubli( S!rin" getDeviceId )* Re!urns !he uniEue de'i(e ID% +or exa$ le% !he IMEI +or GSM and !he MEID or ESN +or 0DMA hones. Re!urn null i+ de'i(e ID is no! a'ailable. ReEuires Per$issionK READZP>ONEZSTATE ubli( S!rin" getDeviceSoftwareVersion )*
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /8@
Re!urns !he so+!&are 'ersion nu$ber +or !he de'i(e% +or exa$ le% !he IMEI3S4 +or GSM hones. Re!urn null i+ !he so+!&are 'ersion is no! a'ailable. ReEuires Per$issionK READZP>ONEZSTATE ubli( S!rin" get#ine'*umber )* Re!urns !he hone nu$ber s!rin" +or line /% +or exa$ le% !he MSISDN +or a GSM hone. Re!urn null i+ i! is una'ailable. ReEuires Per$issionK READZP>ONEZSTATE ubli( S!rin" get*etwor6-ountryIso )* Re!urns !he ISO (oun!r# (ode eEui'alen! o+ !he (urren! re"is!ered o era!orMs M00 )Mobile 0oun!r# 0ode*. A'ailabili!#K Onl# &hen user is re"is!ered !o a ne!&or,. Resul! $a# be unreliable on 0DMA ne!&or,s )use "e!PhoneT# e)*!o de!er$ine i+ on a 0DMA ne!&or,*. ubli( S!rin" get*etwor6Operator )* Re!urns !he nu$eri( na$e )M00LMN0* o+ (urren! re"is!ered o era!or. A'ailabili!#K Onl# &hen user is re"is!ered !o a ne!&or,. Resul! $a# be unreliable on 0DMA ne!&or,s )use "e!PhoneT# e)*!o de!er$ine i+ on a 0DMA ne!&or,*. ubli( S!rin" get*etwor6Operator*ame )* Re!urns !he al habe!i( na$e o+ (urren! re"is!ered o era!or. A'ailabili!#K Onl# &hen user is re"is!ered !o a ne!&or,. Resul! $a# be unreliable on 0DMA ne!&or,s )use "e!PhoneT# e)*!o de!er$ine i+ on a 0DMA ne!&or,*. ubli( in! get*etwor6,ype )* Re!urns a (ons!an! indi(a!in" !he radio !e(hnolo"# )ne!&or, !# e* (urren!l# in use on !he de'i(e +or da!a !rans$ission. 4eturns networ6 type
NETWOR5ZTOPEZUN5NOWN
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /=<
ubli( in! get")one,ype )* Re!urns a (ons!an! indi(a!in" !he de'i(e hone !# e. This indi(a!es !he !# e o+ radio used !o !rans$i! 'oi(e (alls.
ubli( S!rin" getSim-ountryIso )* Re!urns !he ISO (oun!r# (ode eEui'alen! +or !he SIM ro'iderMs (oun!r# (ode. ubli( S!rin" getSimOperator )* Re!urns !he M00LMN0 )$obile (oun!r# (ode L $obile ne!&or, (ode* o+ !he ro'ider o+ !he SIM. 9 or ; de(i$al di"i!s. A'ailabili!#K SIM s!a!e $us! be SIMZSTATEZREADO ubli( S!rin" getSimOperator*ame )* Re!urns !he Ser'i(e Pro'ider Na$e )SPN*. A'ailabili!#K SIM s!a!e $us! be SIMZSTATEZREADO ubli( S!rin" getSimSerial*umber )* Re!urns !he serial nu$ber o+ !he SIM% i+ a una'ailable. li(able. Re!urn null i+ i! is
ReEuires Per$issionK READZP>ONEZSTATE ubli( in! getSimState )* Re!urns a (ons!an! indi(a!in" !he s!a!e o+ !he de'i(e SIM (ard.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /=/
ubli( S!rin" getSubscriberId )* Re!urns !he uniEue subs(riber ID% +or exa$ le% !he IMSI +or a GSM hone. Re!urn null i+ i! is una'ailable. ReEuires Per$issionK READZP>ONEZSTATE ubli( S!rin" getVoice ailAlp)a,ag )* Re!rie'es !he al habe!i( iden!i+ier asso(ia!ed &i!h !he 'oi(e $ail nu$ber. ReEuires Per$issionK READZP>ONEZSTATE ubli( S!rin" getVoice ail*umber )* Re!urns !he 'oi(e $ail nu$ber. Re!urn null i+ i! is una'ailable. ReEuires Per$issionK READZP>ONEZSTATE ubli( boolean )asIcc-ard )* Re!urns true> i+ I00 (ard is resen! ubli( boolean is*etwor64oaming )* Re!urns !rue i+ !he de'i(e is (onsidered roa$in" on !he (urren! ne!&or,% +or GSM ur oses. A'ailabili!#K Onl# &hen user re"is!ered !o a ne!&or,. ubli( 'oid listen )PhoneS!a!eLis!ener lis!ener% in! e'en!s* Re"is!ers a lis!ener obHe(! !o re(ei'e no!i+i(a!ion o+ (han"es in s e(i+ied !ele hon# s!a!es. To re"is!er a lis!ener% ass a PhoneS!a!eLis!ener and s e(i+# a! leas! one !ele hon# s!a!e o+ in!eres! in !he e'en!s ar"u$en!. A! re"is!ra!ion% and &hen a s e(i+ied !ele hon# s!a!e (han"es% !he !ele hon# $ana"er in'o,es !he a ro ria!e (allba(, $e!hod on !he lis!ener obHe(! and asses !he (urren! )ud a!ed* 'alues.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /=8
To unre"is!er a lis!ener% ass !he lis!ener obHe(! and se! !he e'en!s ar"u$en! !o LISTENZNONE )<*. We (an (rea!e Tele hon#Mana"er obHe(! b# usin" "e!S#s!e$Ser'i(e)* $e!hod as +ollo&s.
"ublic
et)ods in! "e!0allS!a!e)* Re!urns a (ons!an! indi(a!in" !he (all s!a!e )(ellular* on !he de'i(e. 0ellLo(a!ion "e!0ellLo(a!ion)* Re!urns !he (urren! lo(a!ion o+ !he de'i(e. in! "e!Da!aA(!i'i!#)* Re!urns a (ons!an! indi(a!in" !he !# e o+ a(!i'i!# on a da!a (onne(!ion )(ellular*. in! "e!Da!aS!a!e)* Re!urns a (ons!an! indi(a!in" !he (urren! da!a (onne(!ion s!a!e )(ellular*. S!rin" "e!De'i(eId)* Re!urns !he uniEue de'i(e ID% +or exa$ le% !he IMEI +or GSM and !he MEID or ESN +or 0DMA hones. S!rin" "e!De'i(eSo+!&are4ersion)* Re!urns !he so+!&are 'ersion nu$ber +or !he de'i(e% +or exa$ le% !he IMEI3S4 +or GSM
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /==
hones. S!rin" "e!Line/Nu$ber)* Re!urns !he hone nu$ber s!rin" +or line /% +or exa$ le% !he MSISDN +or a GSM hone. Lis!QNei"hborin"0ellIn+o "e!Nei"hborin"0ellIn+o)* : Re!urns !he nei"hborin" (ell in+or$a!ion o+ !he de'i(e. S!rin" "e!Ne!&or,0oun!r#Iso)* Re!urns !he ISO (oun!r# (ode eEui'alen! o+ !he (urren! re"is!ered o era!orMs M00 )Mobile 0oun!r# 0ode*. S!rin" "e!Ne!&or,O era!or)* Re!urns !he nu$eri( na$e )M00LMN0* o+ (urren! re"is!ered o era!or. S!rin" "e!Ne!&or,O era!orNa$e)* Re!urns !he al habe!i( na$e o+ (urren! re"is!ered o era!or. in! "e!Ne!&or,T# e)* Re!urns a (ons!an! indi(a!in" !he radio !e(hnolo"# )ne!&or, !# e* (urren!l# in use on !he de'i(e +or da!a !rans$ission. in! "e!PhoneT# e)* Re!urns a (ons!an! indi(a!in" !he de'i(e hone !# e. S!rin" "e!Si$0oun!r#Iso)* Re!urns !he ISO (oun!r# (ode eEui'alen! +or !he SIM ro'iderMs (oun!r# (ode. S!rin" "e!Si$O era!or)* Re!urns !he M00LMN0 )$obile (oun!r# (ode L $obile ne!&or, (ode* o+ !he ro'ider o+ !he SIM. S!rin" "e!Si$O era!orNa$e)* Re!urns !he Ser'i(e Pro'ider Na$e )SPN*. S!rin" "e!Si$SerialNu$ber)*
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /=?
Re!urns !he serial nu$ber o+ !he SIM% i+ a li(able. in! "e!Si$S!a!e)* Re!urns a (ons!an! indi(a!in" !he s!a!e o+ !he de'i(e SIM (ard. S!rin" "e!Subs(riberId)* Re!urns !he uniEue subs(riber ID% +or exa$ le% !he IMSI +or a GSM hone. S!rin" "e!4oi(eMailAl haTa")* Re!rie'es !he al habe!i( iden!i+ier asso(ia!ed &i!h !he 'oi(e $ail nu$ber. S!rin" "e!4oi(eMailNu$ber)* Re!urns !he 'oi(e $ail nu$ber. boolean hasI((0ard)* boolean isNe!&or,Roa$in")* Re!urns !rue i+ !he de'i(e is (onsidered roa$in" on !he (urren! ne!&or,% +or GSM ur oses. 'oid lis!en)PhoneS!a!eLis!ener lis!ener% in! e'en!s* Re"is!ers a lis!ener obHe(! !o re(ei'e no!i+i(a!ion o+ (han"es in s e(i+ied !ele hon# s!a!es.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /=9
aps
Android su or! Lo(a!ion based ser'i(e APIs. Lo(a!ion ser'i(e allo&s !o +ind ou! !he de'i(e (urren! lo(a!ion. The a li(a!ion (an as, +or eriodi( u da!e o+ !he de'i(e lo(a!ion. The a li(a!ion (an also re"is!er a in!en! re(ei'er +or roxi$i!# aler!s li,e &hen !he de'i(e is en!erin" and exis!in" +ro$ an area o+ "i'en lon"i!ude% la!i!ude and radius. Le!-s (he(, !he i$ or!an! (lasses resen! in !he android.lo(a!ion a(,a"e. Android #ocation A"I: Follo&in" are !he so$e i$ or!an! (lasses resen! under !he android lo(a!ion a(,a"e. #ocation anagerK The (lass ro'ides a((ess !o !he lo(a!ion ser'i(e. I! also ro'ides +a(ili!# !o "e! !he bes! Lo(a!ion Pro'ider as er !he (ri!eria. Proxi$i!# aler!s (an be se! )as said abo'e* &i!h hel o+ !his (lass. #ocation"roviderK I!-s an abs!ra(! su er(lass +or lo(a!ion ro'iders. A lo(a!ion ro'ider ro'ides eriodi( re or!s on !he "eo"ra hi(al lo(a!ion o+ !he de'i(e. #ocation#istenerK Pro'ides (allba(, $e!hods &hi(h are (alled &hen lo(a!ion "e!s (han"ed. The lis!ener obHe(! has !o be re"is!ered &i!h !he lo(a!ion $ana"er. -riteriaK The (lass ro'ides !he a li(a!ion !o (hoose sui!able Lo(a!ion Pro'ider
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /=;
Android also ro'ide an API !o a((ess !he Goo"le MAPs. So &i!h !he hel o+ !he Goo"le MAPs and !he lo(a!ion APIs !he a !he user on !he MAP. li(a!ion (an sho& reEuired la(es !o
/oogle
ap A"I
Android de+ines a a(,a"e (alled (o$."oo"le.android.$a s. The a(,a"e (on!ains (lasses rela!ed !o renderin"% (on!rollin" and o'erla#in" in+or$a!ion on !he Goo"le $a s on !he android de'i(es. Le!-s see !he $os! i$ or!an! (lasses de+ined in !he a(,a"eK apActivityK I! is !he s a(in" a(!i'i!# de+ined !o sho& !he Goo"le MAPs. The Ma A(!i'i!# !a,es (are o+ !he lo&1le'el ne!&or,in". apViewK Ma 4ie& is !he 'ie& !ha! su (on!ained b# a Ma A(!i'i!#. ap-ontroller K Ma 0on!roller is !he obHe(! used !o $o'e !he $a around !he s(reen. OverlayK I!-s a dra&able obHe(! !ha! (an be sho&n on !o o+ !he $a . /eo"ointK I!-s a osi!ion in la!i!ude1lon"i!ude. No& &e ha'e so$e basi( ,no&led"e o+ !he Lo(a!ion and Ma APIs% so le!-s (rea!e so$e a A li(a!ionK li(a!ion and see !he$ in a(!ion. or!s and dis la#s !he $a . This $us! be
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /=B
Le!-s de'elo an a
li(a!ion !ha! sho&n !he Goo"le MAP on !he s(reen and sho&s
!he user-s (urren! osi!ion on !he MAP. We &ill use Goo"le MAP APIs !o sho& $a on !he de'i(e and !hen use lo(a!ion APIs !o "e! !he de'i(e (urren! lo(a!ion !o sho& i! on !he MAP. The user lo(a!ion &ill "e!s u da!ed i+ !he user $o'ed +ro$ !he (urren! lo(a!ion.
A li(a!ion A(!i'i!#K To use $a in an a(!i'i!# !ha! a(!i'i!# has !o be ex!ended b# !he Ma A(!i'i!# as sho&n.. (lass M#GPSA(!i'i!# ex!ends Ma A(!i'i!# T ... W To use !he Goo"le MAP APIs% a li(a!ion AndroidMani+es!.x$l +ile $us! de+ine li(a!ion ele$en!K
Quses1librar# androidKna$eYS(o$."oo"le.android.$a sS 3: Usin" !he Ma 4ie&K To dis la# Ma &e need !o add Ma 4ie& !o !he a a(!i'i!#-s la#ou! +ile )$ain.x$l*. Q(o$."oo"le.android.$a s.Ma 4ie& androidKidYNVLid3$#GMa N androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN+illZ aren!N androidKenabledYN!rueN
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /=A
/* Ge! debu".,e#s!ore +ile. Oou &ill "e! !his under USERZ>OMEdLo(al Se!!in"sdA li(a!ion Da!adAndroid dire(!or#. 8* Use ,e#!ool !ool !o "enera!e 0er!i+i(a!e +in"er rin! )MD9*. Use +ollo&in" (o$$and on (o$$and ro$ ! 6eytool 5list 5alias androiddebug6ey 56eystore Jpat)NtoNdebugN6eystoreA%6eystore 5storepass android 56eypass android =* Go !o \Si"n U +or !he Android Ma s API\ a"e. Pu! #our 0er!i+i(a!e +in"er rin! )MD9* And "e! #our API ,e# +or android GMa a ?* Re la(e RAPIZ5e#ZS!rin"S &i!h #our API ,e#. U da!e !he M#GPSA(!i'i!# (lass !o use !he Ma 4ie& (lass M#GPSA(!i'i!# ex!ends Ma A(!i'i!# T VO'erride ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T 33 0rea!in" and ini!iali6in" Ma
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /=@
li(a!ion.
"Ma 4ie& Y )Ma 4ie&* +ind4ie&B#Id)R.id.$#GMa *J GeoPoin! Y ne& GeoPoin!))in!* )la! U /<<<<<<*% )in!* )lon" U /<<<<<<**J "Ma 4ie&.se!Sa!elli!e)!rue*J 33"e! Ma 0on!roller !ha! hel s !o se!3"e! lo(a!ion% 6oo$ e!(. $( Y "Ma 4ie&."e!0on!roller)*J $(.se!0en!er) *J $(.se!Foo$)/?*J W ... W 0er!ain er$ission has !o be se! in !he AndroidMani+es!.x$l +ile !o use lo(a!ion in+or$a!ion. Quses1 er$ission androidKna$eYNandroid. er$ission.INTERNETN:Q3uses1 er$ission: Quses1 er$ission androidKna$eYNandroid. er$ission.A00ESSZ0OARSEZLO0ATIONN:Q3uses1 er$ission: Quses1 er$ission androidKna$eYNandroid. er$ission.A00ESSZFINEZLO0ATIONN:Q3uses1 er$ission: Usin" Lo(a!ion Mana"erK The lo(a!ion $ana"e obHe(! (an be ob!ained &i!h 0on!ex!."e!S#s!e$Ser'i(e $e!hod &i!h 0on!ex!.LO0ATIONZSER4I0E ara$e!er. #ocation anager lm G 7#ocation anager8getSystemService7-onte0t%#O-A,IO*NS.4VI-.8M
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /?<
U da!e !he GPSA(!i'i!# !o i$ le$en! !he Lo(a!ionLis!ener in!er+a(e so !ha! !he a(!i'i!# (an lis!ener !o !he lo(a!ion (han"es. (lass M#GPSA(!i'i!# ex!ends Ma A(!i'i!# i$ le$en!s Lo(a!ionLis!ener T ... 3U This $e!hod is (alled &hen use osi!ion &ill "e! (han"ed U3 ubli( 'oid onLo(a!ion0han"ed)Lo(a!ion lo(a!ion* T W ubli( 'oid onPro'iderDisabled)S!rin" ro'ider* T W ubli( 'oid onPro'iderEnabled)S!rin" ro'ider* T W ubli( 'oid onS!a!us0han"ed)S!rin" ro'ider% in! s!a!us% Bundle ex!ras* T W ro!e(!ed boolean isRou!eDis la#ed)* T re!urn +alseJ W W Le!s add (ode !o ini!iali6e !he Lo(a!ionMana"er and re"is!er !he Lo(a!ion Lis!ener &i!h !he lo(a!ion $ana"er in !he on0rea!e)* $e!hod VO'erride ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T ... Lo(a!ionMana"er l$ Y )Lo(a!ionMana"er*"e!S#s!e$Ser'i(e)0on!ex!.LO0ATIONZSER4I0E*J
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /?/
l$.reEues!Lo(a!ionU da!es)Lo(a!ionMana"er.GPSZPRO4IDER% /<<<L% 9<<.<+% !his*J W No& !he onLo(a!ion0han"ed $e!hod o+ !he GPSA(!i'i!# $e!hod &ill be (alled i+ !he user (han"es i!s osi!ion b# 9<<$. A R" sS )GSPZPRO4IDER* ro'ider is used here bu! #ou (an ob!ain a ro'ider obHe(! as er #our needs &i!h !he "e!Bes!Pro'ider $e!hod o+ !he Lo(a!ionMan"er and !he 0ri!eria obHe(!. >ere is !he i$ le$en!a!ion o+ !he onLo(a!ion0han"ed $e!hod ubli( 'oid onLo(a!ion0han"ed)Lo(a!ion lo(a!ion* T i+ )lo(a!ion [Y null* T double la! Y lo(a!ion."e!La!i!ude)*J double ln" Y lo(a!ion."e!Lon"i!ude)*J Y ne& GeoPoin!))in!* la! U /<<<<<<% )in!* ln" U /<<<<<<*J $(.ani$a!eTo) *J W W The (ode (han"es !he $a lo(a!ion !o !he ne& u da!ed lo(a!ion. We (an add ex!ra !hin"s in our a sho& (urren! lo(a!ion e!(. Addin" Foo$ (on!rolK The MAP a i ro'ides +a(ili!# !o add 6oo$ (on!rol !o !he $a dis la#. Follo&in" (ode add 6oo$ (on!rol !o #our a li(a!ionK li(a!ion li,e Foo$ (on!rols% Mar,er and Tex! !o
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /?8
33 Addin" 6oo$ (on!rols !o Ma Foo$0on!rols 6oo$0on!rols Y )Foo$0on!rols* "Ma 4ie&."e!Foo$0on!rols)*J 6oo$0on!rols.se!La#ou!Para$s)ne& 4ie&Grou .La#ou!Para$s)La#ou!Para$s.WRAPZ0ONTENT% La#ou!Para$s.WRAPZ0ONTENT**J "Ma 4ie&.add4ie&)6oo$0on!rols*J "Ma 4ie&.dis la#Foo$0on!rols)!rue*J Addin" Ma O'erla#K A $a o'erla# (an be added sho&in" !he user-s (urren! lo(a!ion. To add an o'erla#% de+ine a (lass !ha! &ill ex!end O'erla# (lass. (lass M#Lo(a!ionO'erla# ex!ends (o$."oo"le.android.$a s.O'erla# T VO'erride ubli( boolean dra&)0an'as (an'as% Ma 4ie& $a 4ie&% boolean shado&% lon" &hen* T su er.dra&)(an'as% $a 4ie&% shado&*J Pain! ain! Y ne& Pain!)*J 33 0on'er!s la!3ln"1Poin! !o OUR (oordina!es on !he s(reen. Poin! $#S(reen0oords Y ne& Poin!)*J $a 4ie&."e!ProHe(!ion)*.!oPixels) % $#S(reen0oords*J ain!.se!S!ro,eWid!h)/*J ain!.se!ARGB)899% 899% 899% 899*J ain!.se!S!#le)Pain!.S!#le.STRO5E*J Bi!$a b$ Y Bi!$a Fa(!or#.de(odeResour(e)"e!Resour(es)*% R.dra&able.$ar,er*J
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /?=
(an'as.dra&Bi!$a )b$ % $#S(reen0oords.x% $#S(reen0oords.#% ain!*J (an'as.dra&Tex!)N>ere I a$...N% $#S(reen0oords.x% $#S(reen0oords.#% ain!*J re!urn !rueJ W W The o'erla# dis la# a !ex! R>ere I a$..S on !he $a a! user lo(a!ion.Le!-s add !his o'erla# !o our $a 'ie& 33 Add a lo(a!ion $ar, M#Lo(a!ionO'erla# $#Lo(a!ionO'erla# Y ne& M#Lo(a!ionO'erla#)*J Lis!QO'erla#: lis! Y "Ma 4ie&."e!O'erla#s)*J lis!.add)$#Lo(a!ionO'erla#*J 4unning application on .mulator: Run !he e$ula!or ins!an(e. The la!i!ude and lon"i!ude 'alues (an be su e(li se ers e(!i'e. A((ordin" !o la!i!ude and lon"i!ude a lo(a!ion o+ user. lied !o
!he e$ula!or &i!h !he hel o+ \E$ula!or 0on!rol- &indo& resen! in !he DDMS li(a!ion &ill dis la#
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /??
*etwor6 -onnectivity71i3i8
Air!el 4odo+one Ta!a Ne!&or, (onne(!i'i!# GPRS )General o(,e! radio ser'i(e*
Mo'es one la(e !o ano!her la(e !he si"nals &ill be (a!(h one n3& !o ano!her n3& )ne!&or, (arrier or $obile (arrier*. -onnectivity anagerK is !he basi( (lass !o $ana"e !he ne!&or, (onne(!i'i!# ) i! is si$ilar !o !ele hone# $ana"er*. On(e &e "e! !he 0onne(!i'i!#Mana"er% &e (an a((ess !he lo(al (onne(!i'i!# i.eK WiFi android. er$ission.A0ESSZNETWOR5ZSTATE android . er$ission.0>ANGEZNETWOR5ZSTATE De+aul! a((ess !hen &e reEuired A0ESSZNETWOR5ZSTATE is reEuired While (han"in" #ou ne!&or, !hen 0>ANGEZNETWOR5ZSTATE is reEuired While do&nloadin" a +ile% i+ &e (li(, ba(, bu!!on !hen i+ #ou &an! !o (on+ir$ !ha! !as, ba(, "round !hen &e use a se!!in"s.
0onne(!i'i!#Man"er.A0TIONZ BA05GROUNDZ DATAZSTATEZ0>ANGEED. "e!A(!i'eNe!&or,In+o)*J "e!Ne!&or,In+o)*J $e!hods in! "e!PhoneT# es)* TOPEZMOBILE TOPEZWIFI
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /?;
ECTRAZNOZ0ONNE0TI4ITO $ana"er% &e ass ass !hese (ons!an!s ECTRAZNETWOR5ZINFO ECTRAZOT>ERZNETWOR5ZINFO ECTRAZECTRAZINFO
In ot)er end Wi+iMana"er &$Y)Wi+iMana"er*"erS#s!e$Ser'i(e )0on!ex!. WIFIZSER4I0E* isWi+iEnabled)*J "oints: -onnectivity anager The -onnectivity anager "i'es !he in+or$a!ion abou! !he s!a!e o+ ne!&or, (onne(!i'i!#. I! &ill sho& $essa"es !o !he users &ho$ !he ne!&or, (onne(!i'i!# (han"es.
An ins!an(e o+ !he (onne(!i'i!# $ana"er is ob!ained b# (allin" 0on!ex!."e!sS#s!e$Ser'i(e )0on!ex!.0ONNE0TI4ITOZSER4I0E*J -onnectivity anager cmG 7-onnectivity anager8getSystemService -onte0t%-O**.-,IVI,LNS.4VI-.8M The basi( +un(!ionali!# o+ -onnectivity anager (lass are% i! &ill $oni!orin" !he &i+i)&ireless +idi'i!#* GPRS UMTS General Pa(,e! Radio Ser'i(e Uni'ersal Mobile Tele(o$$uni(a!ion s#s!e$
I! is used !o send broad(as! in!en!s &hen !he ne!&or, (onne(!i'i!# $ana"er (han"es I! &ill a!!e$ ! !o s&i!(h o'er !o o!her ne!&or,s &hen !he (onne(!i'i!# is los!. I! ro'ides an API !o Euer# !he% s!a!e o+ !he a'ailable ne!&or,s. Me!hods in -onnectivity anager (lass
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /?B
/. getActive*etwor6Info78: i! re!urns an obHe(! o+ !# e ne!&or, in+o% &hi(h is (urren!l# a(!i'e de'i(e. 8. getAll*etwro6info78M i! re!urns !he ne!&or, (onne(!ions re"is!ered &i!h $obile. =. ger*etwor6Info7int ne!&or,T# e8M i! re!urns an obHe(! o+ !# e ne!&or, in+o% &hi(h des(ribe !he ne!&or, (onne(!ion o+ !he assed ne!&or, !# e. ?. get;ac6groundDataSetting78M i! re!urns !he se!!in" 'alue +or ba(,"round da!a usa"e.i+ i! re!urns +alse% a a li(a!ions should no! use !he ne!&or, i+ !he li(a!ion is no! in !he +ore"round
9. get*etwor6"referance78M i! re!urns !he !# e o+ ne!&or, !o be used &hen $ul!i le ne!&or, (onne(!ions are re"is!ered &i!h de'i(e. ;. set*etwor6"reference78M i! +ixes a re+eren(e le'el on !he ne!&or, (onne(!ion B. is*etwor6,ypeValid7int ne!&or,T# e8M i! re!uns a Boolean 'alue% !rue !he ne!&or, is 'alid. -onstants defined in t)e connectivity manager class ,L".N O;I#. I! is !he de+aul! $obile da!a (onne(!ion% &hen i! is a(!i'e all !he da!a !ra++i( &ill use !his (onne(!ion b# de+aul!. ,L".N O;I#.ND9*: I! is DUN s e(i+i( $obile da!a (onne(!ion. This is used b# !he a er+or$in" a dial u ne!&or,in" (onne(!ion ,L".N O;I#.N+I"4I:
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /?A
li(a!ions
I! is a hi"h riori!# $obile da!a (onne(!ion ,L".N O;I#.N SK Mul!i$edia ser'i(e)MMS* I! is a s e(i+i( $obile This is used b# !he a li(a!ions &hi(h &an! !o !al, !o !he MMS ser'ers. ,L".N1I3I I! is used !o !he de+aul! &i+i (onne(!ion. When i! is a(!i'e all !he da!a !ra++i( &ill be suin" !his (onne(!ion b# de+aul!. ,L".N19I ACK )&orld&ide in!ra abuli!# +or $i(ro&a'e a((ess* I! is used !o ne!&or, ro!o(ol. I! is b# de+aul! &ui$ax da!a (onne(!ion. 1ifi anager: This (lass ro'ides !he basi( API +or $ana"in" &i+i (onne(!i'i!#. An ins!an(e o+ !his (lass (an be (rea!ed b# (allin". -onte0t%getSystemService 7-onte0t%1I3INS.4VI-.8M The basi( +un(!ionali!# o+ !his (lass J /. I! lis!s ou! all !he (on+i"ured ne!&or,s on !he $obile. The lis! i!e$s (an be 'ie& u da!ed. 8. I! sho&s !he (urren!l# a(!i'e &i+i ne!&or,. The d#na$i( in+or$a!ion abou! !he (urren!l# a(!i'e ne!&or, (an be Eueried. =. I! s s(an !he a((ess oin!s a'ailable and i! (on!ains in+or$a!ion abou! a((ess oin! !o (onne(!ion ?. I! de+ines 'arious in!end a(!ions% !ha! are !o be broad (as!ed u on (han"es &i+i s!a!e.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /?@
A*A/.4 -#ASS
=. 1I3INS,A,.N9*K*O1*K &i+i is an un,no&n s!a!e ?. 1I3INS,A,.N.*A;#.DK &i+i is enabled. 9. 1I3INS,A,.N.*A;#I*/K &i+i is (urren!l# bein" enablin". ;. .C,4AN;ASSID ) Basi( ser'i(e se! Iden!i+ier* I! is !he ,e# "i'in" BSSID o+ !he a((ess oin! !o &hi(h &e are (onne(!ed. B. .C,4AN"4.VIO9SN1I3INS,A,.K i! is !he re'ious &i+i s!a!e. A. .C,4AN1I3INS,A,. I! de+ines &he!her &i+i is enable% (lassi+ied% enablin"% disablin" are un,no&n. et)ods in t)e 1ifi anager class /. startScan78: I! reEues!s s(an +or a((ess oin!s. APN )A((ess oin! na$es*. @% set1ifi.nable7true8 ?% get1ifiState78: ?. is1ifi.nabled78: i! re!urns &he!her &i+i is enabled3disabled. 9. getScan4esults78: i! re!urns !he resul!s o+ !he la!es! a((ess oin! s(an ;. get-onnectionInfo78: i! re!urns !he d#na$i( in+or$a!ion abou! !he (urren! &i+i (onne(!ion B. get-onfigured*etwor6s78: i! re!urns a lis! o+ all !he ne!&or, (on+ir"ured A. disable*etwor678: i! disables !he (on+i"ure ne!&or, (onne(!ion. @. disconnect78: i! dis(onne(!s +ro$ !he (urren!l# a(!i'e a((ess oin!. /<. reassociate8K i! re(onne(! (urren!l# a((ess oin! e'en i+ &e are alread# (onne(!ed.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /9<
//. reconnection: i! re(onne(!s !o !he (urren!l# a(!i'e a((ess oin! i+ &e are alread# dis(onne(!ed. Android 1ifi> +ow to scan wireless networ6s2 S(an +or &ireless ne!&or,s in !he (urren! areaK pac6age com%android%wifiM import import import import import import import import import import import import
$ava.util.List% android.app.Activity% android.content.&roadcastReceiver% android.content.!onte't% android.content.Intent% android.content.IntentFilter% android.net.(i)i.ScanResult% android.net.(i)i.*i)iManager% android.os.&undle% android.vie(.Menu% android.vie(.MenuItem% android.(idget.+e't,ie(%
public class Wi+iTes!er e0tends A(!i'i!# T Tex!4ie& $ainTex!J Wi+iMana"er $ainWi+iJ Wi+iRe(ei'er re(ei'erWi+iJ Lis!QS(anResul!: &i+iLis!J S!rin"Builder sb Y new String;uilder)*J public 'oid on-reate)Bundle sa'edIns!an(eS!a!e* T super.on-reate)sa'edIns!an(eS!a!e*J set-ontentView)R.la#ou!.$ain*J $ainTex! Y )Tex!4ie&* findView;yId)R.id.$ainTex!*J $ainWi+i Y )Wi+iMana"er* getSystemService)0on!ex!.WIFIZSER4I0E*J re(ei'erWi+i Y new 1ifi4eceiver)*J register4eceiver)re(ei'erWi+i% new Intent3ilter) Wi+iMana"er.S0ANZRESULTSZA4AILABLEZA0TION**J $ainWi+i.startScan)*J $ainTex!.set,e0t)NdnS!ar!in" S(an...dnN*J
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /9/
W public boolean on-reateOptions enu)Menu $enu* T $enu.add)<% <% <% NRe+reshN*J return super.on-reateOptions enu)$enu*J W public boolean on enuItemSelected)in! +ea!ureId% MenuI!e$ i!e$* T $ainWi+i.startScan)*J $ainTex!.set,e0t)NS!ar!in" S(anN*J return super.on enuItemSelected)+ea!ureId% i!e$*J W protected 'oid on"ause)* T unregister4eceiver)re(ei'erWi+i*J super.on"ause)*J W protected 'oid on4esume)* T register4eceiver)re(ei'erWi+i% new Intent3ilter) Wi+iMana"er.S0ANZRESULTSZA4AILABLEZA0TION**J super.on4esume)*J W class Wi+iRe(ei'er e0tends Broad(as!Re(ei'er T public 'oid on4eceive)0on!ex! (% In!en! in!en!* T sb Y new String;uilder)*J &i+iLis! Y $ainWi+i.getScan4esults)*J for)in! i Y <J i Q &i+iLis!.si<e)*J iLL*T sb.append)new Integer)iL/*.toString)* L N.N*J sb.append))&i+iLis!.get)i**.toString)**J sb.append)NdnN*J W $ainTex!.set,e0t(sb)%
-
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /98
;lue,oot). Blue!oo!h is a (o$$uni(a!ion ro!o(ol% &hi(h is based on Radio Te(hnolo"# a &hi(h is desi"ned +or shor! ran"e% lo& band&id!h (o$$uni(a!ions 3 (onne(!ions)Band&id!h11. 0hannels)ExK89; 5B3/ Mb**J 0onne(!ions are !&o !# es. /* Ad1ho( 0onne(!ion 8* En(ri !ed 0onne(!ion Pi(one!K A $as!er de'i(e &i!h o!her de'i(es )+riendl# na$el#* We (an (onne(! &i!h $axi$u$ six sla'e de'i(es b# usin" Mas!er de'i(es ) In Pi(one! ; $axi$u$ de'i(es*We (an (oun! &i!h nu$ber o+ de'i(es b# usin" sla'e de'i(es ) I! a(!s as a $as!er* Blue!oo!hK Se!!in"s Dis(o'erin" !he de'i(es 0onne(!in" !o de'i(es3Pairin" &i!h de'i(e Trans+errin" !he da!a 0onne(!ions are 8 !# es ) Nor$al (onne(!ion or Adho( 0onne(!ions* and En!er i!id (onne(!ion)B# de+aul! Android su or!s*. ,)e ajor -lass:
/. A((essin" !he Blue!oo!h h3& o+ !he aren! de'i(e. Blue!oo!hAda !er (lass )To a((ess !he lo(al Blue!oo!h hard&are a+!er !ha! re$o!e Blue!oo!h &ill be a((essed* 8. Dis(o'erin" !he re$o!e de'i(e Blue!oo!hDe'i(e (lass =. Sendin"3Trans+erin" !he da!a in one dire(!ion a(!in" as a (lien!
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /9=
Blue!oo!hSo(,e! (lass ?. Trans+erin" !he da!a in bidire(!ional. 9. Blue!oo!hSer'erSo(,e! (lass 8 Per$issions are reEuiredK android. er$ission.BLUETOOT>)A((essin" !he Blue!oo!h er$ission*. android. er$ission.BLUETOOT>ZADMIN)0learin" !he Blue!oo!h er$ission*. In !he ele$en!Quser1 er$ission: !a". Ad1ho( 0onne(!ionK Usin" !his (onne(!ion (o$$uni(a!ion (an $a,e b3& un aired de'i(es. En(ri !ed 0onne(!ionK 0onne(!ions (an be $ade b3& aired de'i(es. The (lasses &hi(h are used !o handle !he Blue!oo!h de'i(es and (onne(!ions are Blue!oo!hAda !erK The lo(al BT de'i(e is (on!rolled usin" !his (lass. To a((ess !he De+aul!Blue!oo!hAda !er% "e!De+aul!Ada !er)* $e!hod (an be (alled on !he lo(al de'i( e. To read !he Blue!oo!hAda !er ro er!ies% !o s!ar! dis(o'er#3!o +ind !he aired de'i(e% one should s e(i+# !he BLUETOOT> Mani+es! er$ission Qusers1 er$ission:. To $odi+# !he an# o+ !he lo(al De'i(e ro er!ies% BLUETOOT>ZADMIN $ani+es! er$ission reEuired. To a((ess !he Blue!oo!hAda !er ro er!ies !he Blue!oo!h should be s&i!(hed on or enabled. We (an (he(, !he s!a!e o+ !he Blue!oo!h h3& usin" !he isEnabled)* $e!hod. The +riendl# na$e o+ !he Blue!oo!hAda !er (an be re!urned usin" !he "e!Na$e)* $e!hod. The Address o+ !he Blue!oo!hAda !er (an be re!ri'ed usin" !he "e!Address)* $e!hod. B# de+aul! !he Blue!oo!hAda !er is TURNEDZOFF.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /9?
The s!a!e o+ !he Blue!oo!hAda !er (an be re!ri'ed b# usin" !he "e!S!a!e)* $e!hod. I! &ill be re!urn one o+ !he +ollo&in" (ons!an!s de+ined in !he Blue!oo!hAda !er (lass. STATEZON STATEZOFF STATEZTURNINGZON STATEZTURNINGZOFF The ro(ess o+ 8 de'i(es +indin" ea(h o!her in order !o (onne(! is (alled Dis(o'erin". /. S!e /K 1 For 8 de'i(es !o air &i!h ea(h o!her !he# need !o be dis(o'ered b# ea(h o!her. 8. S!e 8K 1 A+!er dis(o'erin" ea(h o!her !he Blue!oo!hAda !er o+ Bo!h !he de'i(es is aired &i!h ea(h o!her. =. S!e =K 1 A+!er arin" bo!h !he de'i(es should es!ablish a so(,e! (onne(!ion +or (o$$uni(a!ion. The Blue!oo!hAda !ers dis(o'erabili!# is indi(a!in" b# s(an $ode. We (an re!rie'e !he s(an $ode o+ Ada !er on !he Blue!oo!hAda !er obHe(! b# (allin" "e!S(anMode)* $e!hod. This $e!hod &ill re!urn !he (ons!an!s de+ined in !he Blue!oo!hAda !er (lass. There are 8 !# es o+ S(an $odesK /. InEuir# S(an. 8. Pa"e S(an. InEuir# S(anK I+ !his $ode is enable !he de'i(e is dis(ourable +ro$ an# Blue!oo!h de'i(e. This is er+or$in" a dis(o'er# S(an. Pa"e S(anK I+ !his $ode is enabled de'i(es (an be dis(o'ered !ha! are re'iousl# (onne(!ed and aired &i!h !he lo(al de'i(e. In !his $ode ne& de'i(es (anno! be dis(o'ered.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /99
0ons!an!sK S0ANZMODEZ0ONNE0TABLEZDIS0O4ERABLE K I+ !his (ons!an! is re!urn% I! $eans !ha! bo!h !he s(an $odes are enabled. S0ANZMODEZ0ONNE0TABLEK I+ !his is enabled% i! $eans onl# a"e s(an $ode is enabled. S0ANZMODEZNONEK I! $eans dis(o'erabili!# is !urned o++. I! $eans no o!her de'i(es% &hi(h are ro(ess o+ dis(o'er# s(an +ind !he lo(al de'i(e. B# de+aul! Android de'i(es &ill ha'e diso'erabili!# is disabled. I+ #ou &an! !o $a,e i! dis(o'erable ex li(i! er$ission should be as,ed +ro$ !he user. B# de+aul! dis(o'erabili!# &ill be enabled +or 8 $inu!es. Dis(o'erin" Re$o!e De'i(esK To dis(o'er re$o!e de' i(e !he lo(al Blue!oo!hAda !er is !o be (he(,ed% &he!her i! is alread# er+or$in" a dis(o'erin" s(an. I! is (he(,ed usin" !he isDis(o'erin")* $e!hod. To s!ar! !he dis(o'er# ro(ess (all !he $e!hod s!ar!Dis(o'er# )* $e!hod on !he Blue!oo!hAda !er (lass. To (an(el a Dis(o'er# (all !he (an(elDis(o'er# )* $e!hod on !he Blue!oo!hAda !or (lass. The dis(o'er# ro(ess is async)ronous. Blue!oo!hSo(,e! 0lien! $ode (onne(!ion. Blue!oo!hSer'erSo(,e! Ser'er $ode (onne(!ion. /. S&i!h( on Blue!oo!h. 8. Sear(hin" ar!i(ular de'i(e !o send or re(ei'e da!a. =. Send a reEues!. ?. Pairin" !he de'i(e. >ere &e are sendin" !he da!a)Trans+ers son"*% !hen ho& $u(h _ sendin"% !his &e user Pro"ressDialo" and &e (an (o$$uni(a!e b# usin"
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /9;
Broad(as!Re(ie'er. A+!er !ha! &e re"is!erRe(ie'er)* $e!hod &e (an o'erride re"is!erRe(ie'er)Broad(as!Re(ie'er obHe(!% In!en! obH*J To s!ar! a dis(o'er# !hen &e useKA0TIONZDIS0O4EROZSTARTED To +inish a dis(o'er# !hen &e use To s!ar! a dis(o'er# !hen &e useKA0TIONZDIS0O4EROZFINIS> 33Ini!ia!in" a ser'i(e Blue!oo!hSo(,e! bs Y (rea!eR+(o$$So(,e!ToSer'i(eRe(ord )*J]Radio +reEuen(# (o$$uni(a!ion^ lis!enUsin"R+(o$$&i!hSer'i(eRe(ord)s!rin" na$e% s!rin" UUID*J ]Uni'ersall# UniEuie Iden!i+i(a!ion^ UUID uidY UUID. arse)R>ard&are AddressS*J I+ #ou are &illin" !o air a de'i(e !o !ha! (onne(!ion #es3no. #es $eans a((e !)*$e!hod &ill be (alled. "e!Re$o!eDe'i(e)*J I! is +or &hi(h de'i(es are a'ailable in !he de'i(e. "e!BandedDe'i(es)*J I! re!urns se!% I! sho&s all a!!a(hed de'i(es i! sho&s.
;luetoot) -ommunicaton Blue!oo!h (o$$uni(a!ions &or, a$on" R+(o$% !he Blue!oo!h RadioFreEuen(# (o$$uni(a!ion ro!o(ol. To es!ablish a R+(o$ (onne(!ion% !he +ollo&in" (lasses are reEuired. /. Blue!oo!hSo(,e!K I! is used in (rea!in" a ne& (lien! so(,e! !o (onne(! !o a lis!enin" Blue!oo!hSer'erSo(,e!. I! is re!urned b# !he Ser'erSo(,e! on(e a
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /9B
(onne(!ion is es!ablished. On(e !he (onne(!ion is $ade% Blue!oo!h So(,e!s are used on bo!h end !o Trans+er da!a s!rea$s. 8. Blue!oo!hSer'erSo(,e!K I! is used !o es!ablish a lis!enin" so(,e! +or ini!iall# !he lin, b3& 8 de'i(es. To es!ablish a (onne(!ion one de'i(e a(!s as a ser'er !o lis!en +or and a((e ! in (o$in" (onne(!ion reEues!. O enin" a Blue!oo!hSer'erSo(,e! lis!enerK A Blue!oo!hSer'erSo(,e! is used !o lis!en +or Blue!oo!hSo(,e! (onne(!ion reEues! +ro$ re$o!e Blue!oo!h de'i(es. To lis!en +or in(o$in" (onne(!ion reEues! (all !he Lis!enUsin" R+(o$&i!hSer'i(eRe(ord)* $e!hod on !he Blue!oo!hAda !er (lass. I! !a,es 8 ar"u$en!s /. I! is !he na$e !o iden!i+# !he ser'er and !his &ill re!urn a Blue!oo!hSer'erSo(,e! obHe(!. 8. Uni'ersall# UniEuie Iden!i+i(a!ion)UUID*. To s!ar! lis!enin" +or (onne(!ions% (all a((e !)* on !he Ser'erSo(,e! o !ionall# assin" in a !i$eou! dura!ion. "e!Re$o!eDe'i(e)* $e!hod on #our on !he Blue!oo!hAda !er obHe! re!urns !he Re$o!eDe'i(e. I+ #ou &an! !o (onne(! !o. To +ind !he se! o+ (urren!l# aired de'i(es !o (all "e!BoundedDe'i(e)* $e!hod on lo(al Blue!oo!hAda !er. To s!ar! !he dis(o'er# ro(ess A0TIOZDIS0O4EROZSTARTED In!en! a(!ion is assed% !o +inish !he dis(o'er# ro(ess &an! !o iden!i+# A0TIOZDIS0O4EROZFINIS>ED (alled.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /9A
edia -omponents
-amera
Use a (a$era (o$ onen! !o !a,e a i(!ure on !he hone. 0a$era is a non1'isible (o$ onen! !ha! !a,es a i(!ure usin" !he de'i(eMs (a$era. A+!er !he i(!ure is !a,en% !he a!h !o !he +ile on !he hone (on!ainin" !he i(!ure is a'ailable as an ar"u$en! !o !he A+!erPi(!ure e'en!. The a!h (an be used% +or exa$ le% as !he Pi(!ure ro er!# o+ an I$a"e (o$ onen!. "roperties none et)ods !a,ePi(!ure)* O ens !he honeMs (a$era !o allo& a i(!ure !o be !a,en. .vents a+!erPi(!ure)Tex! i$a"e* 0alled a+!er !he i(!ure is !a,en. The !ex! ar"u$en! i$a"e is !he a!h !ha! (an be used !o lo(a!e !he i$a"e on !he hone. Image"ic6er
Use an i$a"e i(,er (o$ onen! !o (hoose an i$a"e +ro$ #our i$a"e "aller#.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /9@
An i$a"e i(,er is a ,ind o+ bu!!on. When !he user !a s an i$a"e i(,er% !he de'i(eMs i$a"e "aller# a ears% and !he user (an (hoose an i$a"e. A+!er !he user i(,s an i$a"e% !he ro er!# I$a"ePa!h is se! !o a !ex! s!rin" !ha! re resen!s !ha! i$a"e. Oou (an !hen use !ha! resul!% +or exa$ le% !o se! !he i$a"e o+ a bu!!on. "roperties ImagePath The i$a"e !he user (hose% re resen!ed as a !ex! s!rin" !ha! "i'es !he lo(a!ion o+ !he i$a"es. Enabled I+ !rue% i$a"e i(,er (an be used. Ali"n$en! Le+!% (en!er% or ri"h!. Ba(,"round0olor 0olor +or i$a"e i(,er ba(,"round. Enabled I+ se!% user (an !a i$a"e i(,er !o (ause a(!ion. Fon!Bold I+ se!% i$a"e i(,er bu!!on !ex! is dis la#ed in bold. Fon!I!ali( I+ se!% i$a"e i(,er bu!!on !ex! is dis la#ed in i!ali(s. Fon!Si6e Poin! si6e +or i$a"e i(,er bu!!on !ex!. Fon!T# e+a(e Fon! +a$il# +or i$a"e i(,er bu!!on !ex!. >ei"h! i$a"e i(,er bu!!on hei"h! )#1si6e*. Wid!h i$a"e i(,er bu!!on &id!h )x1si6e*. I$a"e I$a"e !o dis la# on i$a"e i(,er bu!!on. Tex! Tex! !o dis la# on i$a"e i(,er bu!!on. Tex!0olor 0olor +or i$a"e i(,er bu!!on !ex!. .vents a+!erPi(,in")*
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /;<
User sele(!ed an i!e$ +ro$ !he i$a"e i(,er. be+orePi(,in")* User has !a ed !he i$a"e i(,er bu! hasnM! #e! sele(!ed an i!e$. "o!Fo(us)* I$a"e i(,er be(a$e !he +o(used (o$ onen!. los!Fo(us)* I$a"e i(,er is no lon"er !he +o(used (o$ onen!. "layer
Use a la#er (o$ onen! !o la# an audio or 'ideo +ile% or !o 'ibra!e !he hone. Pla#er is a non1'isible (o$ onen! !ha! la#s audio or 'ideo and (on!rols hone 'ibra!ion. The na$e o+ a $edia +ile is s e(i+ied in !he Sour(e ro er!#% &hi(h (an be se! in !he Desi"ner or in !he Blo(,s Edi!or. The len"!h o+ !i$e +or a 'ibra!ion is s e(i+ied in !he Blo(,s Edi!or in $illise(onds )!housand!hs o+ a se(ond*. Use a la#er (o$ onen! +or la#in" lon" sound +iles% 'ideo +iles% and 'ibra!in" !he hone. For la#in" shor! sound +iles% su(h as sound e++e(!s% use a Sound (o$ onen! ins!ead. "roperties Sour(e Audio or 'ideo +ile asso(ia!ed &i!h !his la#er. et)ods ause)* Pauses la#in" !he audio or 'ideo +ile. s!ar!)* S!ar!s la#in" !he audio or 'ideo +ile. s!o )* S!o s la#in" !he audio or 'ideo +ile. 'ibra!e)nu$ber $illise(onds* A(!i'a!e !he honeMs 'ibra!ion $o!or +or !he "i'en nu$ber o+ $illise(onds.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /;/
Sound
Use a sound (o$ onen! !o la# an audio +ile% or !o 'ibra!e !he hone. Sound is a non1'isible (o$ onen! !ha! la#s sound +iles and 'ibra!es +or !he nu$ber o+ $illise(onds )!housand!hs o+ a se(ond* s e(i+ied in !he Blo(,s Edi!or. The na$e o+ !he sound +ile !o la# (an be s e(i+ied ei!her in !he Desi"ner or in !he Blo(,s Edi!or. This (o$ onen! is bes! +or shor! sound +iles% su(h as sound e++e(!s% &hile !he Pla#er (o$ onen! is $ore e++i(ien! +or lon"er sounds% su(h as son"s. "roperties Sour(e Audio +ile asso(ia!ed &i!h !his sound. Mini$u$In!er'al Mini$u$ !i$e be+ore sound is re ea!ed. et)ods ause)* Pauses la#in" !he audio +ile. la#)* S!ar!s la#in" !he audio +ile. resu$e)* Resu$es la#in" a aused audio +ile. s!o )* S!o s la#in" !he audio +ile. 'ibra!e)nu$ber $illise(s* A(!i'a!e !he honeMs 'ibra!ion $o!or +or !he "i'en nu$ber o+ $illise(onds.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /;8
Video"layer Use a 4ideoPla#er (o$ onen! !o la# a 'ideo +ile. 4ideo la#er is a $edia (o$ onen! !ha! la#s 'ideos. A 'ideo la#er a ears in #our a as a re(!an"le. I+ !he user !a s !he re(!an"le% $edia (on!rols a earK la#3 ause% s,i ahead% and s,i ba(,&ard. Oour a (an (on!rol la#ba(, beha'ior b# (allin" !he S!ar!% Pause% and S!o $e!hods. 4ideo +iles should be in Windo&s Media 4ideo ).&$'*% =GPP ).=" *% or MPEG1? ).$ ?* +or$a!. For $ore de!ails abou! +or$a!s% see Android Su or!ed Media For$a!s. A In'en!or a((e !s 'ideo +iles u !o / MB in si6e and li$i!s !he !o!al si6e o+ an a !o 9 MB% no! all o+ &hi(h is a'ailable +or $edia +iles. I+ #our $edia +iles are !oo lar"e% #ou $i"h! "e! errors &hen a(,a"in" or ins!allin" #our a % in &hi(h (ase #ou should redu(e !he nu$ber o+ $edia +iles or !heir si6es. 4ideo edi!in" so+!&are% su(h as Windo&s Mo'ie Ma,er or A le iMo'ie% (an hel #ou de(rease !he si6e o+ 'ideos b# shor!enin" !he$ or re1en(odin" !he$ in!o $ore (o$ a(! +or$a!s. "roperties Sour(e 4ideo +ile asso(ia!ed &i!h !his la#er. 4isible I+ se!% 4ideoPla#er is 'isible. et)ods ause)* Pauses la#in" !he 'ideo +ile. s!ar!)* S!ar!s la#in" !he 'ideo +ile. s!o )* S!o s la#in" !he 'ideo +ile.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /;=
Data Storage
The abili!# !o s!ore da!a lo(all# on !he $obile de'i(e is a (ri!i(al +un(!ion +or $obile a li(a!ions !ha! are reEuired !o $ain!ain essen!ial in+or$a!ion a(ross a li(a!ion1exe(u!ions or !he li+e!i$e o+ !he a li(a!ion. As a de'elo er% #ou (ons!an!l# need !o s!ore in+or$a!ion su(h as user re+eren(es or a li(a!ion (on+i"ura!ions. Oou $us! also de(ide i+ #ou need !o !a in!ernal or ex!ernal s!ora"e% de endin" on (hara(!eris!i(s% su(h as a((ess 'isibili!#% or i+ #ou need !o handle $ore (o$ lex% s!ru(!ured !# es o+ da!a. Follo& alon" in !his ar!i(le !o learn abou! Android da!a s!ora"e APIs% s e(i+i(all# !he re+eren(es% SDLi!e% and !he in!ernal and ex!ernal $e$or# APIs. "references :5 Pre+eren(es is a li"h!&ei"h! $e(hanis$ !o s!ore and re!rie'e ,e#1 'alue airs o+ ri$i!i'e da!a !# es. I! is ri'a!e da!a and er$anen! s!ora"e 3iles :5Oou (an s!ore #our da!a in +iles on #our $obile hone% or in a re$o'able s!ora"e $ediu$. I! is also ri'a!e da!a and !e$ orar# s!ora"e. SD -ard :5 I! is ex!ernal s!ora"e s!ored on SD 0ard. I! is ubli( da!a and er$anen! s!ora"e. Databases :5 Android A i su or!s SDLi!e da!abases. All da!abases% SDLi!e and o!hers% are s!ored on !he de'i(e in 3da!a3da!a3 a(,a"eZna$e3da!abases.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /;?
9sing S)ared "references The SharedPre+eren(es (lass ro'ides a "eneral +ra$e&or, !ha! allo&s #ou !o sa'e and re!rie'e ersis!en! ,e#1'alue airs o+ ri$i!i'e da!a !# es. Oou (an use SharedPre+eren(es !o sa'e an# ri$i!i'e da!aK booleans% +loa!s% in!s% lon"s% and s!rin"s. This da!a &ill ersis! a(ross user sessions )e'en i+ #our a li(a!ion is ,illed*. 9ser "references Shared re+eren(es are no! s!ri(!l# +or sa'in" Nuser re+eren(es%N su(h as &ha! rin"!one a user has (hosen. I+ #ouMre in!eres!ed in (rea!in" user re+eren(es +or #our a li(a!ion. To "e! a SharedPre+eren(es obHe(! +or #our a
"e!SharedPre+eren(es)* 1 Use !his i+ #ou need $ul!i le re+eren(es +iles iden!i+ied b# na$e% &hi(h #ou s e(i+# &i!h !he +irs! ara$e!er. "e!Pre+eren(es)* 1 Use !his i+ #ou need onl# one re+eren(es +ile +or #our A(!i'i!#. Be(ause !his &ill be !he onl# re+eren(es +ile +or #our A(!i'i!#% #ou donM! su l# a na$e.
To &ri!e 'aluesK
/. 0all edi!)* !o "e! a SharedPre+eren(es.Edi!or. 8. Add 'alues &i!h $e!hods su(h as u!Boolean)* and u!S!rin")*.
=. 0o$$i! !he ne& 'alues &i!h (o$$i!)* S)ared"references.0ample S)ared"referenceActivity%java a(,a"e (o$. re+eren(esJ i$ or! android.a .A(!i'i!#J i$ or! android.(on!en!.SharedPre+eren(esJ i$ or! android.os.BundleJ i$ or! android.&id"e!.Tex!4ie&J
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /;9
ubli( (lass SharedPre+eren(eA(!i'i!# ex!ends A(!i'i!# T VO'erride ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T su er.on0rea!e)sa'edIns!an(eS!a!e*J se!0on!en!4ie&)R.la#ou!.$ain*J SharedPre+eren(es re+Y"e!Pre+eren(es)MODEZPRI4ATE*J in! (oun!erY re+."e!In!)N(oun!N%<*J Tex!4ie& !'Y)Tex!4ie&*+ind4ie&B#Id)R.id.!ex!4ie&*J !'.se!Tex!)NThis a li(a!ion has been exe(u!ed NL(oun!erLN !i$es.N*J SharedPre+eren(es.Edi!or edi!orY re+.edi!)*J edi!or. u!In!)N(oun!N% LL(oun!er*J edi!or.(o$$i!)*J W W main%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: QLinearLa#ou! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKorien!a!ionYN'er!i(alN androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN+illZ aren!N : QTex!4ie& androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidKidYNVLid3!ex!4ie&N 3: Q3LinearLa#ou!: 3iles79sing t)e Internal Storage8 Oou (an sa'e +iles dire(!l# on !he de'i(eMs in!ernal s!ora"e. B# de+aul!% +iles sa'ed !o !he in!ernal s!ora"e are ri'a!e !o #our a li(a!ion and o!her a li(a!ions (anno! a((ess !he$ )nor (an !he user*. When !he user unins!alls #our a li(a!ion% !hese +iles are re$o'ed.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /;;
This re!urns a FileOu! u!S!rea$. 8. Wri!e !o !he +ile &i!h &ri!e)*. =. 0lose !he s!rea$ &i!h (lose)*. For exa$ leK String FILENAME Y NhelloZ+ileNJ String s!rin" Y Nhello &orld[NJ File.utputStream +os Y o enFileOu! u!)FILENAME% !onte't.MODEZPRI4ATE*J +os.&ri!e)s!rin"."e!B#!es)**J +os.(lose)*J MODEZPRI4ATE &ill (rea!e !he +ile )or re la(e a +ile o+ !he sa$e na$e* and $a,e i! ri'a!e !o #our a li(a!ion. O!her $odes a'ailable areK MODEZAPPEND% MODEZWORLDZREADABLE% and MODEZWORLDZWRITEABLE. To read a +ile +ro$ in!ernal s!ora"eK
/. 0all o enFileIn u!)* and ass i! !he na$e o+ !he +ile !o read. This re!urns a
FileIn u!S!rea$. 8. Read b#!es +ro$ !he +ile &i!h read)*. =. Then (lose !he s!rea$ &i!h (lose)*. ,ip: I+ #ou &an! !o sa'e a s!a!i( +ile in #our a li(a!ion a! (o$ ile !i$e% sa'e !he +ile in #our roHe(! res/ra(/ dire(!or#. Oou (an o en i! &i!h o enRa&Resour(e)*% assin" !he R.ra(.<filename> resour(e ID. This $e!hod re!urns an In u!S!rea$ !ha! #ou (an use !o read !he +ile )bu! #ou (anno! &ri!e !o !he ori"inal +ile*. Sa'in" (a(he +iles I+ #ouMd li,e !o (a(he so$e da!a% ra!her !han s!ore i! ersis!en!l#% #ou should use "e!0a(heDir)* !o o en a File !ha! re resen!s !he in!ernal dire(!or# &here #our a li(a!ion should sa'e !e$ orar# (a(he +iles. When !he de'i(e is lo& on in!ernal s!ora"e s a(e% Android $a# dele!e !hese (a(he +iles !o re(o'er s a(e. >o&e'er% #ou should no! rel# on !he s#s!e$ !o (lean u
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /;B
!hese +iles +or #ou. Oou should al&a#s $ain!ain !he (a(he +iles #oursel+ and s!a# &i!hin a reasonable li$i! o+ s a(e (onsu$ed% su(h as /MB. When !he user unins!alls #our a li(a!ion% !hese +iles are re$o'ed. Ot)er useful met)ods "e!FilesDir)* Ge!s !he absolu!e a!h !o !he +iles#s!e$ dire(!or# &here #our in!ernal +iles are sa'ed. "e!Dir)* 0rea!es )or o ens an exis!in"* dire(!or# &i!hin #our in!ernal s!ora"e s a(e. dele!eFile)* Dele!es a +ile sa'ed on !he in!ernal s!ora"e. +ileLis!)* Re!urns an arra# o+ +iles (urren!l# sa'ed b# #our a li(a!ion. 3ileActivity%java a(,a"e (o$.+ilesJ i$ i$ i$ i$ or! Ha'a.io.Bu++eredReaderJ or! Ha'a.io.Bu++eredWri!erJ or! Ha'a.io.In u!S!rea$ReaderJ or! Ha'a.io.Ou! u!S!rea$Wri!erJ
i$ or! android.a .A(!i'i!#J i$ or! android.os.BundleJ i$ or! android.&id"e!.Tex!4ie&J ubli( (lass FileA(!i'i!# ex!ends A(!i'i!# T VO'erride ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T su er.on0rea!e)sa'edIns!an(eS!a!e*J se!0on!en!4ie&)R.la#ou!.$ain*J !r# T Bu++eredWri!er &ri!er Y ne& Bu++eredWri!er)ne& Ou! u!S!rea$Wri!er)
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /;A
o enFileOu! u!)N$#+ileN% MODEZWORLDZWRITEABLE***J &ri!er.&ri!e)NWel(o$e !o Android/N LNdnN*J &ri!er.&ri!e)NWel(o$e !o Android8N LNdnN*J &ri!er.&ri!e)NWel(o$e !o Android=N LNdnN*J &ri!er.&ri!e)NWel(o$e !o Android?N LNdnN*J &ri!er.&ri!e)NWel(o$e !o Android9N LNdnN*J &ri!er.(lose)*J W (a!(h )Ex(e !ion e* T e. rin!S!a(,Tra(e)*J W !r# T Bu++eredReader in u! Y ne& Bu++eredReader)ne& In u!S!rea$Reader) o enFileIn u!)N$#+ileN***J S!rin" lineJ S!rin"Bu++er sb Y ne& S!rin"Bu++er)*J &hile ))line Y in u!.readLine)** [Y null* T sb.a end)line L NdnN*J W Tex!4ie& !ex!4ie& Y )Tex!4ie&* +ind4ie&B#Id)R.id.resul!*J !ex!4ie&.se!Tex!)sb.!oS!rin")**J W (a!(h )Ex(e !ion e* T e. rin!S!a(,Tra(e)*J W W W SD -ard79sing t)e .0ternal Storage8 E'er# Android1(o$ a!ible de'i(e su or!s a shared Nex!ernal s!ora"eN !ha! #ou (an use !o sa'e +iles. This (an be a re$o'able s!ora"e $edia )su(h as an SD (ard* or an in!ernal )non1re$o'able* s!ora"e. Files sa'ed !o !he ex!ernal s!ora"e are
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /;@
&orld1readable and (an be $odi+ied b# !he user &hen !he# enable USB $ass s!ora"e !o !rans+er +iles on a (o$ u!er. -aution: Ex!ernal +iles (an disa ear i+ !he user $oun!s !he ex!ernal s!ora"e on a (o$ u!er or re$o'es !he $edia% and !hereMs no se(uri!# en+or(ed u on +iles #ou sa'e !o !he ex!ernal s!ora"e. All a li(a!ions (an read and &ri!e +iles la(ed on !he ex!ernal s!ora"e and !he user (an re$o'e !he$. -)ec6ing media availability Be+ore #ou do an# &or, &i!h !he ex!ernal s!ora"e% #ou should al&a#s (all "e!Ex!ernalS!ora"eS!a!e)* !o (he(, &he!her !he $edia is a'ailable. The $edia $i"h! be $oun!ed !o a (o$ u!er% $issin"% read1onl#% or in so$e o!her s!a!e. For exa$ le% hereMs ho& #ou (an (he(, !he a'ailabili!#K boolean $Ex!ernalS!ora"eA'ailable Y +alseJ boolean $Ex!ernalS!ora"eWri!eable Y +alseJ String s!a!e Y #nvironment."e!Ex!ernalS!ora"eS!a!e)*J i+ )#nvironment.MEDIAZMOUNTED.eEuals)s!a!e** T 33 We (an read and &ri!e !he $edia $Ex!ernalS!ora"eA'ailable Y $Ex!ernalS!ora"eWri!eable Y !rueJ W else i+ )#nvironment.MEDIAZMOUNTEDZREADZONLO.eEuals)s!a!e** T 33 We (an onl# read !he $edia $Ex!ernalS!ora"eA'ailable Y !rueJ $Ex!ernalS!ora"eWri!eable Y +alseJ W else T 33 So$e!hin" else is &ron". I! $a# be one o+ $an# o!her s!a!es% bu! all &e need 33 !o ,no& is &e (an nei!her read nor &ri!e $Ex!ernalS!ora"eA'ailable Y $Ex!ernalS!ora"eWri!eable Y +alseJ W This exa$ le (he(,s &he!her !he ex!ernal s!ora"e is a'ailable !o read and &ri!e. The "e!Ex!ernalS!ora"eS!a!e)* $e!hod re!urns o!her s!a!es !ha! #ou $i"h! &an! !o (he(,% su(h as &he!her !he $edia is bein" shared )(onne(!ed !o a (o$ u!er*% is $issin" en!irel#% has been re$o'ed badl#% e!(. Oou (an use !hese !o no!i+# !he user &i!h $ore in+or$a!ion &hen #our a li(a!ion needs !o a((ess !he $edia.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /B<
Accessing files on e0ternal storage I+ #ouMre usin" API Le'el A or "rea!er% use "e!Ex!ernalFilesDir)* !o o en a File !ha! re resen!s !he ex!ernal s!ora"e dire(!or# &here #ou should sa'e #our +iles. This $e!hod !a,es a type ara$e!er !ha! s e(i+ies !he !# e o+ subdire(!or# #ou &an!% su(h as DIRE0TOROZMUSI0 and DIRE0TOROZRINGTONES ) ass null !o re(ei'e !he roo! o+ #our a li(a!ionMs +ile dire(!or#*. This $e!hod &ill (rea!e !he a ro ria!e dire(!or# i+ ne(essar#. B# s e(i+#in" !he !# e o+ dire(!or#% #ou ensure !ha! !he AndroidMs $edia s(anner &ill ro erl# (a!e"ori6e #our +iles in !he s#s!e$ )+or exa$ le% rin"!ones are iden!i+ied as rin"!ones and no! $usi(*. I+ !he user unins!alls #our a li(a!ion% !his dire(!or# and all i!s (on!en!s &ill be dele!ed. I+ #ouMre usin" API Le'el B or lo&er% use "e!Ex!ernalS!ora"eDire(!or#)*% !o o en a File re resen!in" !he roo! o+ !he ex!ernal s!ora"e. Oou should !hen &ri!e #our da!a in !he +ollo&in" dire(!or#K 3Android3da!a3<package_name>3+iles3 The <package_name> is #our Ga'a1s!#le a(,a"e na$e% su(h as Ncom.e'ample.android.appN. I+ !he userMs de'i(e is runnin" API Le'el A or "rea!er and !he# unins!all #our a li(a!ion% !his dire(!or# and all i!s (on!en!s &ill be dele!ed. Saving files t)at s)ould be s)ared I+ #ou &an! !o sa'e +iles !ha! are no! s e(i+i( !o #our a li(a!ion and !ha! should not be dele!ed &hen #our a li(a!ion is unins!alled% sa'e !he$ !o one o+ !he ubli( dire(!ories on !he ex!ernal s!ora"e. These dire(!ories la# a! !he roo! o+ !he ex!ernal s!ora"e% su(h as Music/% 0ictures/% Ringtones/% and o!hers. In API Le'el A or "rea!er% use "e!Ex!ernalS!ora"ePubli(Dire(!or#)*% assin" i! !he !# e o+ ubli( dire(!or# #ou &an!% su(h as DIRE0TOROZMUSI0% DIRE0TOROZPI0TURES% DIRE0TOROZRINGTONES% or o!hers. This $e!hod &ill (rea!e !he a ro ria!e dire(!or# i+ ne(essar#. I+ #ouMre usin" API Le'el B or lo&er% use "e!Ex!ernalS!ora"eDire(!or#)* !o o en a File !ha! re resen!s !he roo! o+ !he ex!ernal s!ora"e% !hen sa'e #our shared +iles in one o+ !he +ollo&in" dire(!oriesK
Music/ 1 Media s(anner (lassi+ies all $edia +ound here as user $usi(.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /B/
0odcasts/ 1 Media s(anner (lassi+ies all $edia +ound here as a od(as!. Ringtones/ 1 Media s(anner (lassi+ies all $edia +ound here as a rin"!one. Alarms/ 1 Media s(anner (lassi+ies all $edia +ound here as an alar$ sound. Noti)ications/ 1 Media s(anner (lassi+ies all $edia +ound here as a no!i+i(a!ion sound. 0ictures/ 1 All ho!os )ex(ludin" !hose !a,en &i!h !he (a$era*. Movies/ 1 All $o'ies )ex(ludin" !hose !a,en &i!h !he (a$(order*. 1o(nload/ 1 Mis(ellaneous do&nloads.
Saving cac)e files I+ #ouMre usin" API Le'el A or "rea!er% use "e!Ex!ernal0a(heDir)* !o o en a File !ha! re resen!s !he ex!ernal s!ora"e dire(!or# &here #ou should sa'e (a(he +iles. I+ !he user unins!alls #our a li(a!ion% !hese +iles &ill be au!o$a!i(all# dele!ed. >o&e'er% durin" !he li+e o+ #our a li(a!ion% #ou should $ana"e !hese (a(he +iles and re$o'e !hose !ha! arenM! needed in order !o reser'e +ile s a(e. I+ #ouMre usin" API Le'el B or lo&er% use "e!Ex!ernalS!ora"eDire(!or#)* !o o en a File !ha! re resen!s !he roo! o+ !he ex!ernal s!ora"e% !hen &ri!e #our (a(he da!a in !he +ollo&in" dire(!or#K 3Android3da!a3<package_name>3(a(he3
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /B8
SD-ard .0ample :5
SD-ardDemo%java a(,a"e (o$.sd(ardJ i$ i$ i$ i$ i$ or! Ha'a.io.UJ or! android.a .A(!i'i!#J or! android.os.BundleJ or! android.'ie&.UJ or! android.'ie&.4ie&.On0li(,Lis!enerJ
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /B=
i$ or! android.&id"e!.UJ ubli( (lass SD0ardDe$o ex!ends A(!i'i!# T 33 GUI (on!rols Edi!Tex! !x!Da!aJ Bu!!on b!nWri!eSDFileJ Bu!!on b!nReadSDFileJ Bu!!on b!n0learS(reenJ Bu!!on b!n0loseJ VO'erride ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T su er.on0rea!e)sa'edIns!an(eS!a!e*J se!0on!en!4ie&)R.la#ou!.$ain*J 33 bind GUI ele$en!s &i!h lo(al (on!rols !x!Da!a Y )Edi!Tex!* +ind4ie&B#Id)R.id.!x!Da!a*J !x!Da!a.se!>in!)NEn!er so$e lines o+ da!a here...N*J b!nWri!eSDFile Y )Bu!!on* +ind4ie&B#Id)R.id.b!nWri!eSDFile*J b!nWri!eSDFile.se!On0li(,Lis!ener)ne& On0li(,Lis!ener)* T ubli( 'oid on0li(,)4ie& '* T 33 &ri!e on SD (ard +ile da!a in !he !ex! box !r# T File $#File Y ne& File)N3sd(ard3$#sd+ile.!x!N*J $#File.(rea!eNe&File)*J FileOu! u!S!rea$ +Ou! Y ne& FileOu! u!S!rea$)$#File*J Ou! u!S!rea$Wri!er $#Ou!Wri!er Y ne& Ou! u!S!rea$Wri!er)+Ou!*J $#Ou!Wri!er.a end)!x!Da!a."e!Tex!)**J $#Ou!Wri!er.(lose)*J +Ou!.(lose)*J Toas!.$a,eTex!)"e!Base0on!ex!)*%NDone &ri!in" SD M$#sd+ile.!x!MN%Toas!.LENGT>ZS>ORT*.sho&)*J W (a!(h )Ex(e !ion e* T
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /B?
Toas!.$a,eTex!)"e!Base0on!ex!)*% e."e!Messa"e)*% Toas!.LENGT>ZS>ORT*.sho&)*J W W33 on0li(, W*J 33 b!nWri!eSDFile b!nReadSDFile Y )Bu!!on* +ind4ie&B#Id)R.id.b!nReadSDFile*J b!nReadSDFile.se!On0li(,Lis!ener)ne& On0li(,Lis!ener)* T ubli( 'oid on0li(,)4ie& '* T 33 &ri!e on SD (ard +ile da!a in !he !ex! box !r# T File $#File Y ne& File)N3sd(ard3$#sd+ile.!x!N*J FileIn u!S!rea$ +In Y ne& FileIn u!S!rea$)$#File*J Bu++eredReader $#Reader Y ne& Bu++eredReader) ne& In u!S!rea$Reader)+In**J S!rin" aDa!aRo& Y NNJ S!rin" aBu++er Y NNJ &hile ))aDa!aRo& Y $#Reader.readLine)** [Y null* T aBu++er LY aDa!aRo& L NdnNJ W !x!Da!a.se!Tex!)aBu++er*J $#Reader.(lose)*J Toas!.$a,eTex!)"e!Base0on!ex!)*%NDone readin" SD M$#sd+ile.!x!MN%Toas!.LENGT>ZS>ORT*.sho&)*J W (a!(h )Ex(e !ion e* T Toas!.$a,eTex!)"e!Base0on!ex!)*% e."e!Messa"e)*% Toas!.LENGT>ZS>ORT*.sho&)*J W W33 on0li(, W*J 33 b!nReadSDFile b!n0learS(reen Y )Bu!!on* +ind4ie&B#Id)R.id.b!n0learS(reen*J b!n0learS(reen.se!On0li(,Lis!ener)ne& On0li(,Lis!ener)* T ubli( 'oid on0li(,)4ie& '* T 33 (lear !ex! box
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /B9
!x!Da!a.se!Tex!)NN*J W W*J 33 b!n0learS(reen b!n0lose Y )Bu!!on* +ind4ie&B#Id)R.id.b!n0lose*J b!n0lose.se!On0li(,Lis!ener)ne& On0li(,Lis!ener)* T ubli( 'oid on0li(,)4ie& '* T 33 (lear !ex! box +inish)*J W W*J 33 b!n0lose W33 on0rea!e W33 AndSD(ard
main%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: QLinearLa#ou! androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN+illZ aren!N androidKba(,"roundYN2++<<<<++N androidKorien!a!ionYN'er!i(alN x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN : QEdi!Tex! androidKidYNVLid3!x!Da!aN androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN/A< xN androidK!ex!Si6eYN/As N 3: QBu!!on androidKidYNVLid3b!nWri!eSDFileN androidKla#ou!Z&id!hYN/?= xN androidKla#ou!Zhei"h!YN?? xN androidK!ex!YN/. Wri!e SD FileN 3: QBu!!on androidKidYNVLid3b!n0learS(reenN
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /B;
androidKla#ou!Z&id!hYN/?/ xN androidKla#ou!Zhei"h!YN?8 xN androidK!ex!YN8. 0lear S(reenN 3: QBu!!on androidKidYNVLid3b!nReadSDFileN androidKla#ou!Z&id!hYN/?< xN androidKla#ou!Zhei"h!YN?8 xN androidK!ex!YN=. Read SD FileN 3: QBu!!on androidKidYNVLid3b!n0loseN androidKla#ou!Z&id!hYN/?/ xN androidKla#ou!Zhei"h!YN?= xN androidK!ex!YN?. 0loseN 3: Q3LinearLa#ou!: S=#iteDatabase 3or Android Android a li(a!ions (an s!ore a li(a!ion da!a in SDLi!e da!abases. In !his !u!orial% #ou learn ho& SDLi!e da!abases are desi"ned and $ani ula!ed. >ere &e be"in b# desi"nin" and usin" a si$ le SDLi!e da!abase !o $ana"e (hess !ourna$en! s(ores. This !u!orial is $ean! as a brie+ o'er'ie& o+ ho& SDLi!e da!abases &or,. This ,no&led"e &ill !hen be used in +u!ure de'elo $en! !u!orials !o i$ le$en! da!abase1dri'en Android a li(a!ions. /etting Started Android a li(a!ions (an (rea!e and $ani ula!e !heir o&n ri'a!e SDLi!e rela!ional da!abases. De'elo ers (an also ins e(! and $odi+# da!abases on a "i'en Android e$ula!or or de'i(e usin" !he sEli!e= (o$$and1line !ool ro'ided as ar! o+ !he Android SD5 !ool (alled Android Debu" Brid"e )adb*. In !his &e assu$e !ha! #ou ha'e so$e unders!andin" o+ rela!ional da!abases% in !heor#% bu! reEuire a bi! o+ a re+resher (ourse be+ore #ou use !he$ &i!hin #our Android a li(a!ions. This ar!i(ular !u!orial does no! reEuire an# !oolsJ i!-s $ore a !heore!i(al exer(ise. >o&e'er% i+ #ou are lannin" !o de'elo Android a li(a!ions &hi(h rel# u on SDLi!e da!abases% #ou &ill need !o ins!all !he !ools ne(essar# +or Android de'elo $en!% su(h as !he Android SD5 and !he E(li se IDE.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /BB
1)at is S=#ite2 SDLi!e is a li"h!&ei"h! rela!ional da!abase en"ine. SDLi!e is +as! and has a s$all +oo! rin!% $a,in" i! er+e(! +or Android de'i(es. Ins!ead o+ !he hea'#&ei"h! ser'er1based da!abases li,e Ora(le and Mi(roso+! SDL Ser'er% ea(h SDLi!e da!abase is s!ored &i!hin a sin"le +ile on dis,. Android a li(a!ions (an (hoose !o s!ore ri'a!e a li(a!ion da!a in a SDLi!e da!abase. No!eK I+ #ou-re +a$iliar &i!h SDL% !hen SDLi!e &ill be 'er# eas# !o i(, u . SDLi!e is basi(all# a s!ri ed1do&n SDL da!abase en"ine +or e$bedded de'i(es. . A =uic6 4eview of Database 3undamentals A da!abase is si$ l# a s!ru(!ured &a# o+ s!orin" da!a in a ersis!en! +ashion. Da!a is s!ored in !ables. A !able has (olu$ns &i!h di++eren! da!a!# es. Ea(h ro& in a !able re resen!s a da!a re(ord. Oou $a# +ind i! hel +ul !o !hin, o+ a !able li,e an Ex(el s readshee!. For an obHe(! orien!ed ro"ra$$in" ers e(!i'e% ea(h !able in a da!abase o+!en re resen!s an obHe(! )re resen!ed b# a (lass*. Ea(h !able (olu$n re resen!s a (lass a!!ribu!e. Ea(h re(ord in a !able re resen!s a s e(i+i( ins!an(e o+ !ha! obHe(!. Le!-s loo, a! a Eui(, exa$ le. Le!-s sa# #ou ha'e a (o$ an# da!abase &i!h a !able (alled E$ lo#ee. The E$ lo#ee !able $i"h! ha'e +i'e !# ed (olu$nsK E$ lo#eeID )nu$ber*% Firs!Na$e )s!rin"*% Las!Na$e )s!rin"*% Ti!le )s!rin"* and Salar# )nu$ber*. Oou (ould !hen add a re(ord !o !he da!a base +or an e$ lo#ee na$ed Gohn Doe and a se ara!e re(ord +or an e$ lo#ee na$ed Anne Droid. Da!a &i!hin a da!abase is $ean! !o be ins e(!ed and $ani ula!ed. Da!a &i!hin a !able (an beK Added )usin" !he INSERT (o$$and* Modi+ied )usin" !he UPDATE (o$$and* Re$o'ed )usin" !he DELETE (o$$and* Oou (an sear(h +or s e(i+i( da!a &i!hin a da!abase usin" &ha! is (alled a Euer#. A Euer# )usin" !he SELE0T (o$$and* $a# in'ol'e one !able% or $ul!i le !ables. To (rea!e a Euer#% #ou $us! s e(i+# !he !ables% da!a (olu$ns% and da!a 'alues o+ in!eres! usin" SDL (o$$and lan"ua"e. Ea(h SDL (o$$and is !er$ina!ed &i!h a se$i(olon )J*. ,)e -)ess ,ournament Database The bes! &a# !o !rul# unders!and ho& SDLi!e da!abases +un(!ion is !o &or, !hrou"h a si$ le exa$ le% so le!-s do so. Le!-s re!end !ha! &e ha'e an a li(a!ion !ha! ,ee s !ra(, o+ la#er s(ores +ro$ a (asual (hess !ourna$en!. Pla#er s(ores are
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /BA
re(orded and !hen% a! !he end o+ a series o+ $a!(hes% !he &inner is de!er$ined. Ea(h la#er-s o'erall !ourna$en! s(ore is (al(ula!ed +ro$ !heir er+or$an(e onK Four &ar$1u hea!s )&ei"h!K /<_ o+ o'erall s(ore ea(h* One se$i1+inal )&ei"h!K 89_ o+ o'erall s(ore* One +inal )&ei"h!K =9_ o+ o'erall s(ore* No!eK For !he !ourna$en!% la#er s(ores (ould be based u on a +or$ula !ha! +a(!ors in !he !i$e i! !oo, !o &in !he "a$e and !he !# e and nu$ber o+ ie(es le+! on !he board a! !he end o+ !he "a$e. This &a#% a s!ron" la#er &ill re(ei'e a hi"h s(ore +or losin" +e& o&er+ul ie(es and &innin" !he "a$e Eui(,l#. Perha s s!#le and a!!i!ude are in(luded b# !he Hud"es !o en(oura"e +un% li"h! la#. >o& s(ores are (al(ula!ed is reall# no! i$ or!an! !o ho& &e de+ine our da!abaseJ &e Hus! s!ore !he$ in !he da!abase. For si$ li(i!#% &e &ill assu$e !ha! s(ores are based on a s(ale o+ <I/<<. Designing t)e Database Sc)ema A da!abase s(he$a is si$ l# !he de+ini!ion o+ !he s!ru(!ure o+ !he da!abase in !er$s o+ !ables% da!a (olu$ns and su(h. The s(he$a +or our !ourna$en! da!abase is Eui!e si$ leK The Tourna$en!S(ores da!abase s(he$a has !hree !ablesK The Pla#ers !able (on!ains la#er in+or$a!ion. The Ga$es !able (on!ains in+or$a!ion abou! ea(h "a$e and ho& $u(h i! (oun!s !o&ard !he la#er-s o'erall !ourna$en! s(ore. The Ga$eResul!s !able (on!ains all la#ers- "a$e s(ores. S=#ite? )as support for t)e following common datatypes for columns: INTEGER )si"ned in!e"ers* REAL )+loa!in" oin! 'alues* TECT )UTF1A or UTF1/; s!rin"J en(oded usin" da!abase en(odin"* BLOB )da!a (hun,* On(e #ou-'e de!er$ined &hi(h (olu$ns are ne(essar# +or ea(h !able% #ou-re read# !o (rea!e so$e !ables &i!hin #our da!abase s(he$a. 1or6ing wit) ,ables Le!-s be"in b# (rea!in" !he Pla#ers !able. This !able reEuires a uniEue la#er id !o re+eren(e ea(h la#er. We (an $a,e !his !he ri$ar# ,e# )!o uniEuel# iden!i+# a re(ord in !his !able* and se! i!s au!oin(re$en! a!!ribu!e. Au!oin(re$en! $eans !ha! ea(h !i$e a ne& la#er re(ord is added% !he re(ord &ill "e! a ne&% uniEue la#er
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /B@
id. We also &an! !o s!ore !he +irs! and las! na$e o+ ea(h la#er1no nulls allo&ed. >ere &e (an use !he 0REATE TABLE SDL s!a!e$en! !o "enera!e !he Pla#ers !ableK 0REATE TABLE Pla#ers ) id INTEGER PRIMARO 5EO AUTOIN0REMENT% +na$e TECT NOT NULL% lna$e TECT NOT NULL *J The Ga$es !able is 'er# si$ilar. We need a uniEue "a$e id !o re+eren(e ea(h "a$e. We also &an! a +riendl# na$e +or ea(h "a$e and a &ei"h! 'alue +or ho& $u(h !he "a$e (oun!s !o&ards !he la#er-s +inal !ourna$en! s(ore )as a er(en!a"e*. >ere-s !he SDL s!a!e$en! !o (rea!e !he Ga$es !ableK 0REATE TABLE Ga$es ) id INTEGER PRIMARO 5EO AUTOIN0REMENT% "a$ena$e TECT% &ei"h! REAL DEFAULT ./< 0>E05 )&ei"h!QY/**J Oou (an also dele!e !ables usin" !he DROP TABLE s!a!e$en!. For exa$ le% !o dele!e !he Ga$es !able% use !he +ollo&in" SDL (o$$andK DROP TABLE Ga$esJ "opulating ,ables wit) Data 4ecords Be+ore &e $o'e on% le!-s add so$e da!a !o !hese !ables. To add a re(ord !o !he Pla#ers !able% #ou need !o s e(i+# !he (olu$n na$es and !he 'alues in order. For exa$ le% !he +ollo&in" SDL s!a!e$en! uses !he INSERT (o$$and !o add a re(ord +or (hess la#er Bobb# FisherK INSERT in!o Pla#ers )+na$e% lna$e* 4ALUES )MBobb#M% MFisherM*J While &e-re add i!% &e-ll add !&o $ore la#ersK Bar! Si$ son )a 'er# i!i+ul (hess la#er* and Garr# 5as aro' ) erha s !he bes! (hess la#er e'er*. A! !he sa$e !i$e% &e need !o add a bun(h o+ re(ords !o !he Ga$es !able. Firs! &e add !he se$i1 +inal% &hi(h (oun!s +or 89 er(en! o+ !he la#er-s !ourna$en! s(oreK INSERT in!o Ga$es )"a$ena$e% &ei"h!* 4ALUES )MSe$i1FinalM% .89*J Then &e add a (ou le &ar$1u hea!s% &hi(h use !he de+aul! &ei"h! o+ /< er(en!K INSERT in!o Ga$es )"a$ena$e* 4ALUES )MWar$1u >ea! /M*J Finall#% &e add a +inal &or!h =9 er(en! o+ !he !o!al !ourna$en! s(oreK
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /A<
INSERT in!o Ga$es )"a$ena$e% &ei"h!* 4ALUES )MFinalM% .=9*J =uerying ,ables for 4esults wit) S.#.-, >o& do &e ,no& !he da!a &e-'e added is in !he !ableX Well% !ha!-s eas#. We si$ l# Euer# +or all ro&s in a !able usin" a SELE0T s!a!e$en!K SELE0T U FROM Ga$esJ This re!urns all re(ords in !he Ga$es !ableK id "a$ena$e &ei"h! 11111 111111111111111 111111 / Se$i1Final <.89 8 War$1u >ea! / <./ = War$1u >ea! 8 <./ 9sing -olumn Aliases and -alculated -olumns We (an also (rea!e our o&n (olu$ns and alias !he$. For exa$ le% &e (an (rea!e a (olu$n alias (alled Pla#erNa$e !ha! is a (al(ula!ed (olu$nK I!-s !he la#er-s +irs! and las! na$es (on(a!ena!ed usin" !he cc o era!or% se ara!ed b# a s a(eK SELE0T +na$eccM Mcc lna$e AS Pla#erNa$e% id FROM Pla#ersJ This Euer# rodu(es !he +ollo&in" resul!sK Pla#erNa$e id 111111111111 111 Bobb# Fisher / Bar! Si$ sen 8 Garr# 5as aro' = Altering Data in ,ables Bar!-s ) la#er id 8* las! na$e is s elled in(orre(!l#. To u da!e !he Pla#ers !able !o re+le(! !he (orre(! s ellin"% #ou (an use !he UPDATE (o$$andK UPDATE Pla#ers SET lna$eYMSi$ sonM W>ERE la#eridY8J Oou (an dele!e ro&s +ro$ a !able usin" !he DELETE +un(!ion. For exa$ le% !o dele!e !he re(ord &e Hus! u da!edK DELETE FROM Pla#ers W>ERE la#eridY8J Oou (an dele!e all ro&s in a !able b# no! s e(i+#in" !he W>ERE (lauseK
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /A/
DELETE FROM Pla#ersJ 9sing 3oreign Keys and -omposite Keys No& !ha! &e ha'e our Pla#ers and Ga$es all se! u % le!-s (rea!e !he Ga$eResul!s !able. This is a $ore (o$ li(a!ed !able. The Ga$eResul!s !able airs u la#er ids +ro$ !he Pla#ers !able &i!h "a$e ids +ro$ !he Ga$es !able and !hen lis!s !he s(ore !ha! !he la#er earned +or !he s e(i+i( "a$e. 0olu$ns% &hi(h lin, !o o!her !ables in !his &a#% are o+!en (alled +orei"n ,e#s. We &an! uniEue la#er1"a$e airin"s% so &e (rea!e a (o$ osi!e ri$ar# ,e# +ro$ !he la#er and "a$e +orei"n ,e#s% !o uniEuel# iden!i+# a Ga$eResul!s re(ord. Las!l#% &e en+or(e !ha! !he s(ores are &hole nu$bers be!&een < and /<<. 0REATE TABLE Ga$eResul!s ) la#erid INTEGER REFEREN0ES Pla#ers)id*% "a$eid INTEGER REFEREN0ES Ga$es)id*% s(ore INTEGER 0>E05 )s(oreQY/<< AND s(ore:Y<*% PRIMARO 5EO ) la#erid% "a$eid**J )No!eK SDLi!e does no! en+or(e +orei"n ,e# (ons!rain!s% bu! #ou (an se! !he$ u an#&a# and en+or(e !he (ons!rain!s b# (rea!in" !ri""ers.* No& i!-s !i$e !o inser! so$e da!a !o !he Ga$eResul!s !able. Le!-s sa# Bobb# Fisher ) la#er id /* re(ei'ed a s(ore o+ A8 oin!s on !he se$i1+inal )"a$e id /*. Oou (ould use !he +ollo&in" SDL (o$$and !o inser! !he a ro ria!e re(ord in!o !he Ga$eResul!s !ableK INSERT in!o Ga$eResul!s ) la#erid% "a$eid% s(ore* 4ALUES )/%/%A8*J No& le!-s assu$e !he !ourna$en! is la#ed and !he s(ores are added !o !he Ga$eResul!s !able. Bobb# is a "ood la#er% Bar! is a !errible la#er% and Garr# al&a#s la#s a er+e(! "a$e. On(e !he re(ords ha'e been added !o !he Ga$eResul!s !able% &e (an er+or$ a SELE0T U (o$$and !o lis! all re(ords in !he !able% or &e (an s e(i+# (olu$ns ex li(i!l# li,e !hisK SELE0T la#erid% "a$eid% s(ore FROM Ga$eResul!sJ >ere are !he resul!s +ro$ !his Euer#K la#erid "a$eid s(ore 1111111111 1111111111 11111 / / A8 / 8 AA / = BA / ? @<
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /A8
/ 9 A9 / ; @? 8 / /< 8 8 ;< 8 = 9< 8 ? 99 8 9 ?9 = 9 /<< = ? /<< = = /<< = 8 /<< = / /<< As #ou (an see% !his lis!in" is no! ar!i(ularl# Rhu$an1readableS. =uerying Across ultiple ,ables 9sing !OI* Wouldn-! i! be $ore hel +ul i+ !he na$es o+ !he la#ers and Ga$es &ere sho&n ins!ead o+ !heir nu$eri( idsX Duer#in" and (o$binin" da!a in SELE0T s!a!e$en!s is o+!en handled b# er+or$in" a GOIN &i!h $ul!i le !able sour(esJ !here are di++eren! ,inds o+ GOINS. When #ou &or, &i!h $ul!i le !ables% #ou need !o s e(i+# &hi(h !able !ha! a (olu$n belon"s !o )es e(iall# &hen (olu$ns are na$ed !he sa$e% su(h as &i!h all !hese di++eren! id (olu$ns*. Oou (an re+er !o (olu$ns b# !heir (olu$n na$e or b# !heir !able na$e% !hen a do! ).*% and !hen !he (olu$n na$e. Le!-s relis! !he la#er s(ores a"ain% onl# !his !i$e% in(lude !he na$e o+ !he "a$e and !he na$e o+ !he la#er. Also% &e li$i! our resul!s onl# !o !he s(ore +or !he Final )"a$e id ;*K SELE0T Pla#ers.+na$eccM Mcc Pla#ers.lna$e AS Pla#erNa$e% Ga$es."a$ena$e% Ga$eResul!s.s(ore FROM Ga$eResul!s GOIN Pla#ers ON )Ga$eResul!s. la#eridYPla#ers.id* GOIN Ga$es ON )Ga$eResul!s."a$eidYGa$es.id* W>ERE "a$eidY;J &hi(h "i'es us !he +ollo&in" resul!s )#ou (ould lea'e o++ !he W>ERE !o "e! all Ga$es*K Pla#erNa$e "a$ena$e s(ore 111111111111111111 11111111111111 11111
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /A=
@? ;9 /<<
-onclusion This (on(ludes our ex lora!ion o+ a si$ le SDLi!e da!abase exa$ leK a (hess !ourna$en! da!abase. >o e+ull# #ou-'e rea(Euain!ed #oursel+ &i!h rela!ional da!abase (on(e !s li,e !ables% re(ords% and Eueries and +a$iliari6ed #oursel+ &i!h $an# o+ !he (o$$onl# used SDLi!e (o$$ands. Finall#% #ou-'e &al,ed !hrou"h !he desi"n and usa"e o+ an exa$ le da!abase. No& !ha! #ou-'e "o! a handle on ho& SDLi!e da!abases &or,% #ou-re read# !o use !he$ &i!hin #our Android a li(a!ions .
S=#iteDatabase.0ample
Database+elper%java
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /A?
a(,a"e (o$.dbJ i$ or! android.(on!en!.0on!ex!J i$ or! android.da!abase.sEli!e.SDLi!eDa!abaseJ i$ or! android.da!abase.sEli!e.SDLi!eO en>el erJ ubli( (lass Da!abase>el er ex!ends SDLi!eO en>el er T ubli( s!a!i( +inal S!rin" DATAZBASEYNM#da!abase.dbNJ ubli( s!a!i( +inal S!rin" TABLEZNAMEYNS!uden!NJ ubli( s!a!i( +inal in! DATABASEZ4ERSION Y/J ubli( Da!abase>el er)0on!ex! (on!ex!* T su er)(on!ex!% DATAZBASE% null% DATABASEZ4ERSION*J W VO'erride ubli( 'oid on0rea!e)SDLi!eDa!abase db* T db.exe(SDL)N0REATE TABLE N L TABLEZNAME L N)Na$e TECT% AGE NUMERI0% ADDRESS TECT*N*J W VO'erride ubli( 'oid onU "rade)SDLi!eDa!abase db% in! old4ersion% in! ne&4ersion* T W W main%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: QLinearLa#ou! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKorien!a!ionYN'er!i(alN androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN+illZ aren!N androidKba(,"round Y N2++++++N :
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /A9
QTex!4ie& androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidK!ex!YNSTUDENT INFORMATIONN androidK!ex!0olorYN2<<<<<<N 3: QTableRo& androidKidYNVLid3!ableRo&/N androidKla#ou!Z&id!hYN$a!(hZ aren!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N: QTex!4ie& androidK!ex!YNNAME N androidKidYNVLid3!ex!4ie&/N androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidK!ex!0olorYN2<<<<<<N: Q3Tex!4ie&: QEdi!Tex! androidK!ex!YNN androidKidYNVLid3edi!Tex!/N androidKla#ou!Zhei"h!YN9< xN androidKla#ou!Z&id!hYN/8< xN :Q3Edi!Tex!: Q3TableRo&: QTableRo& androidKidYNVLid3!ableRo&/N androidKla#ou!Z&id!hYN$a!(hZ aren!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N: QTex!4ie& androidK!ex!YNAGE N androidKidYNVLid3!ex!4ie&8N androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidK!ex!0olorYN2<<<<<<N: Q3Tex!4ie&: QEdi!Tex! androidK!ex!YNN androidKidYNVLid3edi!Tex!8N androidKla#ou!Zhei"h!YN9< xN androidKla#ou!Z&id!hYN/8< xN: Q3Edi!Tex!: Q3TableRo&: QTableRo& androidKidYNVLid3!ableRo&/N
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /A;
androidKla#ou!Z&id!hYN$a!(hZ aren!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N: QTex!4ie& androidK!ex!YNAddressN androidKidYNVLid3!ex!4ie&=N androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidK!ex!0olorYN2<<<<<<N: Q3Tex!4ie&: QEdi!Tex! androidKla#ou!Z&id!hYN/8< xN androidK!ex!YNN androidKidYNVLid3edi!Tex!=N androidKla#ou!Zhei"h!YN9< xN : Q3Edi!Tex!: Q3TableRo&: QTableRo& androidKidYNVLid3!ableRo&8N androidKla#ou!Z&id!hYN$a!(hZ aren!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N: QBu!!on androidK!ex!YNsa'eN androidKidYNVLid3sa'eBu!!onN androidKla#ou!Z&id!hYN9< xN androidKla#ou!Zhei"h!YN9< xN : Q3Bu!!on: QBu!!on androidKla#ou!Z&id!hYNA< xN androidKla#ou!Zhei"h!YN9< xN androidKidYNVLid3de!ailsBu!!onN androidK!ex!YNDe!ailsN: Q3Bu!!on: Q3TableRo&: Q3LinearLa#ou!: Database9se%java a(,a"e (o$.dbJ i$ i$ i$ i$ or! android.a .A(!i'i!#J or! android.a .Aler!Dialo"J or! android.(on!en!.In!en!J or! android.da!abase.sEli!e.SDLi!eDa!abaseJ
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /AB
i$ i$ i$ i$ i$ i$ i$
or! android.da!abase.sEli!e.SDLi!eS!a!e$en!J or! android.os.BundleJ or! android.'ie&.4ie&J or! android.'ie&.4ie&.On0li(,Lis!enerJ or! android.&id"e!.Bu!!onJ or! android.&id"e!.Edi!Tex!J or! android.&id"e!.Toas!J
ubli( (lass Da!abaseUse ex!ends A(!i'i!# i$ le$en!s On0li(,Lis!ener T Bu!!on sub$i!%re!ri'eJ Aler!Dialo" diJ ri'a!e SDLi!eDa!abase sELi!eDa!abaseJ ri'a!e SDLi!eS!a!e$en! sELi!eS!a!e$en!J ri'a!e S!rin" na$e% a"e% address J ri'a!e s!a!i( +inal S!rin" TABLEZNAME Y NS!uden!NJ ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T su er.on0rea!e)sa'edIns!an(eS!a!e*J se!0on!en!4ie&)R.la#ou!.$ain*J sub$i!Y)Bu!!on*+ind4ie&B#Id)R.id.sa'eBu!!on*J re!ri'eY)Bu!!on*+ind4ie&B#Id)R.id.de!ailsBu!!on*J Da!abase>el er db Y ne& Da!abase>el er)!his*J sELi!eDa!abase Y db."e!Wri!ableDa!abase)*J sELi!eS!a!e$en! Y sELi!eDa!abase.(o$ ileS!a!e$en!) Ninser! in!o NL TABLEZNAME L N)na$e% a"e% address * 'alues )X% X% X*N*J sub$i!.se!On0li(,Lis!ener)!his*J re!ri'e.se!On0li(,Lis!ener)!his*J W ubli( 'oid on0li(,)4ie& '* T
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /AA
s&i!(h )'."e!Id)** T (ase R.id.de!ailsBu!!onK In!en! inYne& In!en!)"e!A li(a!ion0on!ex!)*% Dis la#A(!i'i!#.(lass*J s!ar!A(!i'i!#)in*J brea,J (ase R.id.sa'eBu!!onK na$e Y ))Edi!Tex!*+ind4ie&B#Id)R.id.edi!Tex!/**."e!Tex!)*.!oS!rin")*.!ri$)*J a"eY ))Edi!Tex!*+ind4ie&B#Id)R.id.edi!Tex!8**."e!Tex!)*.!oS!rin")*.!ri$)*J address Y ))Edi!Tex!*+ind4ie&B#Id)R.id.edi!Tex!=**."e!Tex!)*.!oS!rin")*.!ri$)*J sELi!eS!a!e$en!.bindS!rin")/% na$e*J sELi!eS!a!e$en!.bindS!rin")8% a"e*J sELi!eS!a!e$en!.bindS!rin")=% address*J sELi!eS!a!e$en!.exe(u!eInser!)*J Toas!.$a,eTex!)"e!A li(a!ion0on!ex!)*% NDa!a sa'edN% Toas!.LENGT>ZS>ORT*.sho&)*J W W W display%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: QLinearLa#ou! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /A@
DisplayActivity%java a(,a"e (o$.dbJ i$ i$ i$ i$ i$ i$ i$ i$ i$ or! Ha'a.u!il.Arra#Lis!J or! android.a .A(!i'i!#J or! android.da!abase.0ursorJ or! android.da!abase.sEli!e.SDLi!eDa!abaseJ or! android.da!abase.sEli!e.SDLi!eEx(e !ionJ or! android.os.BundleJ or! android.u!il.Lo"J or! android.&id"e!.Arra#Ada !erJ or! android.&id"e!.Lis!4ie&J
ri'a!e Arra#Lis!QS!rin": arra#Lis! Y ne& Arra#Lis!QS!rin":)*J ri'a!e SDLi!eDa!abase M#da!abaseJ Lis!4ie& lis!4ie&J VO'erride ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T su er.on0rea!e)sa'edIns!an(eS!a!e*J se!0on!en!4ie&)R.la#ou!.dis la#*J lis!4ie&Y)Lis!4ie&*+ind4ie&B#Id)R.id.lis!4ie&*J 33o enAndDuer#Da!abase !r# T Da!abase>el er db Y ne& Da!abase>el er)!his*J 33O en !he da!abase M#da!abase Y db."e!Wri!ableDa!abase)*J 0ursor ( Y M#da!abase.ra&Duer#)NSELE0T U FROM S!uden!N% null*J i+ )( [Y null * T i+ )(.$o'eToFirs!)** T do T S!rin" Na$e Y (."e!S!rin")(."e!0olu$nIndex)NNa$eN**J in! a"e Y (."e!In!)(."e!0olu$nIndex)NAGEN**J S!rin" address Y (."e!S!rin")(."e!0olu$nIndex)NADDRESSN**J arra#Lis!.add)NNa$e K N L Na$e LNdnNL NA"e K N La"e LNdnNL NAddressK N L addressLNdnN*J W&hile )(.$o'eToNex!)**J W W W (a!(h )SDLi!eEx(e !ion se * T Lo".e)"e!0lass)*."e!Si$ leNa$e)*% N0ould no! (rea!e or N LNO en !he da!abaseN*J W +inall# T i+ )M#da!abase [Y null* 33M#da!abase.exe(SDL)NDELETE FROM STUDENTN*J
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /@/
M#da!abase.(lose)*J W 33dis la#Resul!Lis! lis!4ie&.se!Ada !er)ne& Arra#Ada !erQS!rin":)!his% android.R.la#ou!.si$ leZlis!Zi!e$Z/% arra#Lis!**J W W
Animations An ani$a!ion resour(e (an de+ine one o+ !&o !# es o+ ani$a!ionsK Pro er!# Ani$a!ion 0rea!es an ani$a!ion b# $odi+#in" an obHe(!Ms ro er!# 'alues o'er a se! eriod o+ !i$e &i!h an Ani$a!or. 4ie& Ani$a!ion There are !&o !# es o+ ani$a!ions !ha! #ou (an do &i!h !he 'ie& ani$a!ion +ra$e&or,K T&een ani$a!ionK 0rea!es an ani$a!ion b# er+or$in" a series o+ !rans+or$a!ions on a sin"le i$a"e &i!h an Ani$a!ion
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /@8
Fra$e ani$a!ionK or (rea!es an ani$a!ion b# sho&in" a seEuen(e o+ i$a"es in order &i!h an Ani$a!ionDra&able.
,ween animation An ani$a!ion de+ined in CML !ha! er+or$s !ransi!ions su(h as ro!a!in"% +adin"% $o'in"% and s!re!(hin" on a "ra hi(.
FILE LO0ATIONK
QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: Qse! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKin!er ola!orYNV] a(,a"eK^ani$3interpolator_resourceN androidKshareIn!er ola!orY]N!rueN c N+alseN^ : Qal ha androidK+ro$Al haYNfloatN androidK!oAl haYNfloatN 3: Qs(ale androidK+ro$CS(aleYNfloatN androidK!oCS(aleYNfloatN androidK+ro$OS(aleYNfloatN androidK!oOS(aleYNfloatN androidK i'o!CYNfloatN androidK i'o!OYNfloatN 3: Q!ransla!e androidK+ro$CDel!aYNfloatN androidK!oCDel!aYNfloatN androidK+ro$ODel!aYNfloatN androidK!oODel!aYNfloatN 3:
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /@=
Qro!a!e androidK+ro$De"reesYNfloatN androidK!oDe"reesYNfloatN androidK i'o!CYNfloatN androidK i'o!OYNfloatN 3: Qse!: ... Q3se!: Q3se!: The +ile $us! ha'e a sin"le roo! ele$en!K ei!her an6alp7a8% 6scale8% 6translate8%6rotate8% or 6set8 ele$en! !ha! holds a "rou )or "rou s* o+ o!her ani$a!ion ele$en!s )e'en nes!ed 6set8 ele$en!s*. ELEMENTSK Qse!: A (on!ainer !ha! holds o!her ani$a!ion ele$en!s )6alp7a8% 6scale8% 6translate8%6rotate8* or o!her 6set8 ele$en!s. Re resen!s an Ani$a!ionSe!.
ATTRIBUTESK
androidKin!er ola!or Interpolator resource. An In!er ola!or !o a l# on !he ani$a!ion. The 'alue $us! be a re+eren(e !o a resour(e !ha! s e(i+ies an in!er ola!or )no! an in!er ola!or (lass na$e*. There are de+aul! in!er ola!or resour(es a'ailable +ro$ !he la!+or$ or #ou (an (rea!e #our o&n in!er ola!or resour(e. See !he dis(ussion belo& +or $ore abou! In!er ola!ors. androidKshareIn!er ola!or oolean. N!rueN i+ #ou &an! !o share !he sa$e in!er ola!or a$on" all (hild ele$en!s. Qal ha: A +ade1in or +ade1ou! ani$a!ion. Re resen!s an Al haAni$a!ion.
ATTRIBUTESK
androidK+ro$Al ha !loat. S!ar!in" o a(i!# o++se!% &here <.< is !rans aren! and /.< is o aEue. androidK!oAl ha !loat. Endin" o a(i!# o++se!% &here <.< is !rans aren! and /.< is o aEue.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /@?
For $ore a!!ribu!es su or!ed b# 6alp7a8% see !heAni$a!ion (lass re+eren(e )o+ &hi(h% all CML a!!ribu!es are inherri!ed b# !his ele$en!*. Qs(ale: A resi6in" ani$a!ion. Oou (an s e(i+# !he (en!er oin! o+ !he i$a"e +ro$ &hi(h i! "ro&s ou!&ard )or in&ard* b# s e(i+#in" pivot9 and pivot:. For exa$ le% i+ !hese 'alues are <% < )!o 1le+! (orner*% all "ro&!h &ill be do&n and !o !he ri"h!. Re resen!s a S(aleAni$a!ion.
ATTRIBUTESK
androidK+ro$CS(ale !loat. S!ar!in" C si6e o++se!% &here /.< is no (han"e. androidK!oCS(ale !loat. Endin" C si6e o++se!% &here /.< is no (han"e. androidK+ro$OS(ale !loat. S!ar!in" O si6e o++se!% &here /.< is no (han"e. androidK!oOS(ale !loat. Endin" O si6e o++se!% &here /.< is no (han"e. androidK i'o!C !loat. The C (oordina!e !o re$ain +ixed &hen !he obHe(! is s(aled. androidK i'o!O !loat. The O (oordina!e !o re$ain +ixed &hen !he obHe(! is s(aled. For $ore a!!ribu!es su or!ed b# 6scale8% see !heAni$a!ion (lass re+eren(e )o+ &hi(h% all CML a!!ribu!es are inherri!ed b# !his ele$en!*. Q!ransla!e: A 'er!i(al and3or hori6on!al $o!ion. Su or!s !he +ollo&in" a!!ribu!es in an# o+ !he +ollo&in" !hree +or$a!sK 'alues +ro$ 1/<< !o /<< endin" &i!h N_N% indi(a!in" a er(en!a"e rela!i'e !o i!sel+J 'alues +ro$ 1/<< !o /<< endin" in N_ N% indi(a!in" a er(en!a"e rela!i'e !o i!s aren!J a +loa! 'alue &i!h no su++ix% indi(a!in" an absolu!e 'alue. Re resen!s a Transla!eAni$a!ion.
ATTRIBUTESK
androidK+ro$CDel!a !loat or percentage. S!ar!in" C o++se!. Ex ressed ei!herK in ixels rela!i'e !o !he nor$al osi!ion )su(h as ;<;*% in er(en!a"e rela!i'e !o !he ele$en!
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /@9
&id!h )su(h as;<=;*% or in er(en!a"e rela!i'e !o !he aren! &id!h )su(h as ;<=p;*. androidK!oCDel!a !loat or percentage. Endin" C o++se!. Ex ressed ei!herK in ixels rela!i'e !o !he nor$al osi!ion )su(h as ;<;*% in er(en!a"e rela!i'e !o !he ele$en! &id!h )su(h as;<=;*% or in er(en!a"e rela!i'e !o !he aren! &id!h )su(h as ;<=p;*. androidK+ro$ODel!a !loat or percentage. S!ar!in" O o++se!. Ex ressed ei!herK in ixels rela!i'e !o !he nor$al osi!ion )su(h as ;<;*% in er(en!a"e rela!i'e !o !he ele$en! hei"h! )su(h as;<=;*% or in er(en!a"e rela!i'e !o !he aren! hei"h! )su(h as ;<=p;*. androidK!oODel!a !loat or percentage. Endin" O o++se!. Ex ressed ei!herK in ixels rela!i'e !o !he nor$al osi!ion )su(h as ;<;*% in er(en!a"e rela!i'e !o !he ele$en! hei"h! )su(h as;<=;*% or in er(en!a"e rela!i'e !o !he aren! hei"h! )su(h as ;<=p;*. For $ore a!!ribu!es su or!ed b# 6translate8% see !heAni$a!ion (lass re+eren(e )o+ &hi(h% all CML a!!ribu!es are inherri!ed b# !his ele$en!*. Qro!a!e: A ro!a!ion ani$a!ion. Re resen!s a Ro!a!eAni$a!ion.
ATTRIBUTESK
androidK+ro$De"rees !loat. S!ar!in" an"ular osi!ion% in de"rees. androidK!oDe"rees !loat. Endin" an"ular osi!ion% in de"rees. androidK i'o!C !loat or percentage. The C (oordina!e o+ !he (en!er o+ ro!a!ion. Ex ressed ei!herK in ixels rela!i'e !o !he obHe(!Ms le+! ed"e )su(h as ;<;*% in er(en!a"e rela!i'e !o !he obHe(!Ms le+! ed"e )su(h as ;<=;*% or in er(en!a"e rela!i'e !o !he aren! (on!ainerMs le+! ed"e )su(h as ;<=p;*. androidK i'o!O
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /@;
!loat or percentage. The O (oordina!e o+ !he (en!er o+ ro!a!ion. Ex ressed ei!herK in ixels rela!i'e !o !he obHe(!Ms !o ed"e )su(h as ;<;*% in er(en!a"e rela!i'e !o !he obHe(!Ms !o ed"e )su(h as ;<=;*% or in er(en!a"e rela!i'e !o !he aren! (on!ainerMs !o ed"e )su(h as ;<=p;*. For $ore a!!ribu!es su or!ed b# 6rotate8% see !heAni$a!ion (lass re+eren(e )o+ &hi(h% all CML a!!ribu!es are inherri!ed b# !his ele$en!*. ECAMPLEK CML +ile sa'ed a! res/anim/7yperspace>$ump.'mlK Qse! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKshareIn!er ola!orYN+alseN: Qs(ale androidKin!er ola!orYNVandroidKani$3a((elera!eZde(elera!eZin!er ola!orN androidK+ro$CS(aleYN/.<N androidK!oCS(aleYN/.?N androidK+ro$OS(aleYN/.<N androidK!oOS(aleYN<.;N androidK i'o!CYN9<_N androidK i'o!OYN9<_N androidK+illA+!erYN+alseN androidKdura!ionYNB<<N 3: Qse! androidKin!er ola!orYNVandroidKani$3a((elera!eZin!er ola!orN androidKs!ar!O++se!YNB<<N: Qs(ale androidK+ro$CS(aleYN/.?N androidK!oCS(aleYN<.<N androidK+ro$OS(aleYN<.;N androidK!oOS(aleYN<.<N androidK i'o!CYN9<_N androidK i'o!OYN9<_N androidKdura!ionYN?<<N 3: Qro!a!e androidK+ro$De"reesYN<N androidK!oDe"reesYN1?9N androidK!oOS(aleYN<.<N androidK i'o!CYN9<_N
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /@B
androidK i'o!OYN9<_N androidKdura!ionYN?<<N 3: Q3se!: Q3se!: This a li(a!ion (ode &ill a !he ani$a!ionK l# !he ani$a!ion !o an I$a"e4ie& and s!ar!
I$a"e4ie& i$a"e Y )I$a"e4ie&* +ind4ie&B#Id)R.id.i$a"e*J Ani$a!ion h# ers a(eGu$ Y Ani$a!ionU!ils.loadAni$a!ion)!his% R.ani$.h# ers a(eZHu$ *J i$a"e.s!ar!Ani$a!ion)h# ers a(eGu$ *J
,weenAnimation .0ample
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /@A
main%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: QLinearLa#ou! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKorien!a!ionYN'er!i(alN androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN+illZ aren!N : QTex!4ie& androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidK!ex!YNWel(o$eN androidK!ex!0olorYN2<<++<<N androidK!ex!Si6eYN=< xN androidKidYNVLid3!ex!4ie&N 3: QI$a"e4ie& androidKidYNVLid3i$a"e4ie&N androidKla#ou!Z&id!hYN&ra Z(on!en!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidKsr(YNVdra&able3i$a"esandroidroboN3: Q3LinearLa#ou!:
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e /@@
custom%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: Jset x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKshareIn!er ola!orYN+alseN: Q[11 Qal ha androidK+ro$Al haYN<.;N androidK!oAl haYN/.<N androidKdura!ionYN?<<<N: Q3al ha: 11: Q[11Qs(ale androidK i'o!CYN/9<_N androidK i'o!OYN89<_N androidK+ro$CS(aleYN./N androidK+ro$OS(aleYN./N androidK!oCS(aleYN/.<N androidK!oOS(aleYN/.<N androidKdura!ionYN8<<<<N 3: 11: Qro!a!e androidK+ro$De"reesYN<N androidK!oDe"reesYNB8<N androidK i'o!CYN9<_N androidK i'o!OYN9<_N androidKdura!ionYN=<<<<N 3: J:setA
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 8<<
,weenAnimationActivity%java a(,a"e (o$.ani$a!ionJ i$ or! android.a .A(!i'i!#J i$ or! android.os.BundleJ i$ or! android.'ie&.ani$a!ion.Ani$a!ionJ i$ or! android.'ie&.ani$a!ion.Ani$a!ionU!ilsJ i$ or! android.&id"e!.I$a"e4ie&J i$ or! android.&id"e!.Tex!4ie&J ubli( (lass T&eenAni$a!ionA(!i'i!# ex!ends A(!i'i!# T VO'erride ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T su er.on0rea!e)sa'edIns!an(eS!a!e*J se!0on!en!4ie&)R.la#ou!.$ain*J I$a"e4ie& i$"Y)I$a"e4ie&*+ind4ie&B#Id)R.id.i$a"e4ie&*J Tex!4ie& !'Y)Tex!4ie&*+ind4ie&B#Id)R.id.!ex!4ie&*J Ani$a!ion ani$a!ionYAni$a!ionU!ils.loadAni$a!ion)!his%R.ani$.(us!o$*J 33i$".s!ar!Ani$a!ion)ani$a!ion*J !'.s!ar!Ani$a!ion)ani$a!ion*J W W
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 8</
3rame animation An ani$a!ion de+ined in CML !ha! sho&s a seEuen(e o+ i$a"es in order )li,e a +il$*.
FILE LO0ATIONK
QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: Qani$a!ion1lis! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKonesho!Y]N!rueN c N+alseN^ : Qi!e$ androidKdra&ableYNV] a(,a"eK^dra&able3drawable_resource_nameN androidKdura!ionYNintegerN 3: Q3ani$a!ion1lis!:
ELEMENTSK
Qani$a!ion1lis!: 4eFuired. This $us! be !he roo! ele$en!. 0on!ains one or $ore6item8 ele$en!s.
ATTRIBUTESK
androidKonesho! oolean. N!rueN i+ #ou &an! !o er+or$ !he ani$a!ion on(eJ N+alseN !o loo !he ani$a!ion. Qi!e$: A sin"le +ra$e o+ ani$a!ion. Mus! be a (hild o+ a 6animation?list8 ele$en!.
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 8<8
androidKdra&able "rawable resource. The dra&able !o use +or !his +ra$e. androidKdura!ion Integer. The dura!ion !o sho& !his +ra$e% in $illise(onds.
ECAMPLEK
CML +ile sa'ed a! res/anim/rocket.'mlK QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: Qani$a!ion1lis! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKonesho!YN+alseN: Qi!e$ androidKdra&ableYNVdra&able3ro(,e!Z!hrus!/N androidKdura!ionYN8<<N 3: Qi!e$ androidKdra&ableYNVdra&able3ro(,e!Z!hrus!8N androidKdura!ionYN8<<N 3: Qi!e$ androidKdra&ableYNVdra&able3ro(,e!Z!hrus!=N androidKdura!ionYN8<<N 3: Q3ani$a!ion1lis!: This a li(a!ion (ode &ill se! !he ani$a!ion as !he ba(,"round +or a 4ie&% !hen la# !he ani$a!ionK I$a"e4ie& ro(,e!I$a"e Y )I$a"e4ie&* +ind4ie&B#Id)R.id.ro(,e!Zi$a"e*J ro(,e!I$a"e.se!Ba(,"roundResour(e)R.dra&able.ro(,e!Z!hrus!*J ro(,e!Ani$a!ion Y )Ani$a!ionDra&able* ro(,e!I$a"e."e!Ba(,"round)*J ro(,e!Ani$a!ion.s!ar!)*J
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 8<=
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 8<?
3rameAnimations%java a(,a"e (o$.ani$a!ionJ i$ i$ i$ i$ i$ i$ or! android.a .A(!i'i!#J or! android."ra hi(s.dra&able.Ani$a!ionDra&ableJ or! android.os.BundleJ or! android.'ie&.4ie&J or! android.&id"e!.Bu!!onJ or! android.&id"e!.I$a"e4ie&J
ubli( (lass Fra$eAni$a!ions ex!ends A(!i'i!# T VO'erride ubli( 'oid on0rea!e)Bundle sa'edIns!an(eS!a!e* T su er.on0rea!e)sa'edIns!an(eS!a!e*J se!0on!en!4ie&)R.la#ou!.$ain*J Bu!!on b Y )Bu!!on*!his.+ind4ie&B#Id)R.id.s!ar!FABu!!onId*J b.se!On0li(,Lis!ener)ne& Bu!!on.On0li(,Lis!ener)* T ubli( 'oid on0li(,)4ie& '* T I$a"e4ie& i$"4ie& Y )I$a"e4ie&*+ind4ie&B#Id)R.id.ani$a!ionI$a"e*J i$"4ie&.se!Ba(,"roundResour(e)R.dra&able.+ra$eZani$a!ion*J Ani$a!ionDra&able +ra$eAni$a!ion Y )Ani$a!ionDra&able* i$"4ie&."e!Ba(,"round)*J i+ )+ra$eAni$a!ion.isRunnin")** T +ra$eAni$a!ion.s!o )*J W else T +ra$eAni$a!ion.s!ar!)*J W W W*J W W
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 8<9
custom%0ml Qani$a!ion1lis! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKonesho!YN+alseN: Qi!e$ androidKdra&ableYNVdra&able3d/N androidKdura!ionYN89<N 3: Qi!e$ androidKdra&ableYNVdra&able3d8N androidKdura!ionYN/9<N 3: Qi!e$ androidKdra&ableYNVdra&able3d=N androidKdura!ionYN89<N 3: Qi!e$ androidKdra&ableYNVdra&able3d?N androidKdura!ionYN?9<N 3: Qi!e$ androidKdra&ableYNVdra&able3d9N androidKdura!ionYN9<N 3: Qi!e$ androidKdra&ableYNVdra&able3d;N androidKdura!ionYN9<N 3: Qi!e$ androidKdra&ableYNVdra&able3dBN androidKdura!ionYN89<N 3: Qi!e$ androidKdra&ableYNVdra&able3dAN androidKdura!ionYN<N 3: Qi!e$ androidKdra&ableYNVdra&able3d@N androidKdura!ionYN/9<N 3: Qi!e$ androidKdra&ableYNVdra&able3d/<N androidKdura!ionYN/9<N 3: Q3ani$a!ion1lis!: main%0ml QXx$l 'ersionYN/.<N en(odin"YNu!+1ANX: QLinearLa#ou! x$lnsKandroidYNh!! K33s(he$as.android.(o$3a ,3res3androidN androidKorien!a!ionYN'er!i(alN androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN+illZ aren!N: QTex!4ie& androidKidYNVLid3!ex!4ie&Id/N androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidK!ex!YNFra$e B# Fra$e Ani$a!ion o+ /< Du,esN3: QBu!!on androidKidYNVLid3s!ar!FABu!!onIdN androidKla#ou!Z&id!hYN+illZ aren!N androidKla#ou!Zhei"h!YN&ra Z(on!en!N androidK!ex!YNS!ar! Du,e Ani$a!ionN 3: QI$a"e4ie& androidKidYNVLid3ani$a!ionI$a"eN
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 8<;
DURGA SOFTWARE SOLUTIONS, S.R NAGAR, HYD-38 Cell: 9246212143, 4 64!12"86 #$%e 8<B