外文文献Android Application Fundamentals安卓应用基础.docx
《外文文献Android Application Fundamentals安卓应用基础.docx》由会员分享,可在线阅读,更多相关《外文文献Android Application Fundamentals安卓应用基础.docx(25页珍藏版)》请在冰豆网上搜索。
外文文献AndroidApplicationFundamentals安卓应用基础
外文文献-AndroidApplicationFundamentals安卓应用基础
毕业设计
外文文献原文及译文
AndroidApplicationFundamentals
安卓应用基础
学生姓名:
学号:
计算机系系别:
网络工程专业:
指导教师:
2015年5月
中北大学信息商务学院2015届毕业设计外文文献原文及译文
AndroidApplicationFundamentals
AndroidapplicationsarewrittenintheJavaprogramminglanguage.TheAndroidSDKtoolscompilethecode—alongwithanydataandresourcefiles—intoanAndroidpackage,
anarchivefilewithan.apksuffix.Allthecodeinasingle.apkfileisconsideredtobeoneapplicationandisthefilethatAndroid-powereddevicesusetoinstalltheapplication.
Onceinstalledonadevice,eachAndroidapplicationlivesinitsownsecuritysandbox:
TheAndroidoperatingsystemisamulti-userLinuxsysteminwhicheach
applicationisadifferentuser.
Bydefault,thesystemassignseachapplicationauniqueLinuxuserID(theIDis
usedonlybythesystemandisunknowntotheapplication).Thesystemsets
permissionsforallthefilesinanapplicationsothatonlytheuserIDassignedto
thatapplicationcanaccessthem.
Eachprocesshasitsownvirtualmachine(VM),soanapplication'scoderunsin
isolationfromotherapplications.
Bydefault,everyapplicationrunsinitsownLinuxprocess.Androidstartsthe
processwhenanyoftheapplication'scomponentsneedtobeexecuted,thenshuts
downtheprocesswhenit'snolongerneededorwhenthesystemmustrecover
memoryforotherapplications.
Inthisway,theAndroidsystemimplementstheprincipleofleastprivilege.Thatis,
eachapplication,bydefault,hasaccessonlytothecomponentsthatitrequirestodoitsworkandnomore.Thiscreatesaverysecureenvironmentinwhichanapplicationcannotaccesspartsofthesystemforwhichitisnotgivenpermission.
However,therearewaysforanapplicationtosharedatawithotherapplicationsandforanapplicationtoaccesssystemservices:
It'spossibletoarrangefortwoapplicationstosharethesameLinuxuserID,in
whichcasetheyareabletoaccesseachother'sfiles.Toconservesystemresources,
中北大学信息商务学院2015届毕业设计外文文献原文及译文
applicationswiththesameuserIDcanalsoarrangetoruninthesameLinux
processandsharethesameVM(theapplicationsmustalsobesignedwiththe
samecertificate).
Anapplicationcanrequestpermissiontoaccessdevicedatasuchastheuser's
contacts,SMSmessages,themountablestorage(SDcard),camera,Bluetooth,and
more.Allapplicationpermissionsmustbegrantedbytheuseratinstalltime.ThatcoversthebasicsregardinghowanAndroidapplicationexistswithinthesystem.Therestofthisdocumentintroducesyouto:
Thecoreframeworkcomponentsthatdefineyourapplication.
Themanifestfileinwhichyoudeclarecomponentsandrequireddevicefeatures
foryourapplication.
Resourcesthatareseparatefromtheapplicationcodeandallowyourapplication
togracefullyoptimizeitsbehaviorforavarietyofdeviceconfigurations.
ApplicationComponents
ApplicationcomponentsaretheessentialbuildingblocksofanAndroidapplication.Eachcomponentisadifferentpointthroughwhichthesystemcanenteryourapplication.Notallcomponentsareactualentrypointsfortheuserandsomedependoneachother,buteachoneexistsasitsownentityandplaysaspecificrole—eachoneisauniquebuilding
blockthathelpsdefineyourapplication'soverallbehavior.
Therearefourdifferenttypesofapplicationcomponents.Eachtypeservesadistinctpurposeandhasadistinctlifecyclethatdefineshowthecomponentiscreatedanddestroyed.
Herearethefourtypesofapplicationcomponents:
Activities
Anactivityrepresentsasinglescreenwithauserinterface.Forexample,anemail
applicationmighthaveoneactivitythatshowsalistofnewemails,anotheractivity
中北大学信息商务学院2015届毕业设计外文文献原文及译文
tocomposeanemail,andanotheractivityforreadingemails.Althoughtheactivitiesworktogethertoformacohesiveuserexperienceintheemailapplication,eachoneisindependentoftheothers.Assuch,adifferentapplicationcanstartanyoneoftheseactivities(iftheemailapplicationallowsit).Forexample,acameraapplicationcanstarttheactivityintheemailapplicationthatcomposesnewmail,inorderfortheusertoshareapicture.
AnactivityisimplementedasasubclassofActivityandyoucanlearnmoreaboutitintheActivitiesdeveloperguide.
Services
Aserviceisacomponentthatrunsinthebackgroundtoperformlong-runningoperationsortoperformworkforremoteprocesses.Aservicedoesnotprovideauserinterface.Forexample,aservicemightplaymusicinthebackgroundwhiletheuserisinadifferentapplication,oritmightfetchdataoverthenetworkwithoutblockinguserinteractionwithanactivity.Anothercomponent,suchasanactivity,canstarttheserviceandletitrunorbindtoitinordertointeractwithit.AserviceisimplementedasasubclassofServiceandyoucanlearnmoreaboutitintheServicesdeveloperguide.
Contentproviders
Acontentprovidermanagesasharedsetofapplicationdata.Youcanstorethedatainthefilesystem,anSQLitedatabase,ontheweb,oranyotherpersistentstoragelocationyourapplicationcanaccess.Throughthecontentprovider,otherapplicationscanqueryorevenmodifythedata(ifthecontentproviderallowsit).Forexample,theAndroidsystemprovidesacontentproviderthatmanagestheuser'scontactinformation.Assuch,anyapplicationwiththeproperpermissionscanquerypartofthecontentprovider(suchasContactsContract.Data)toreadandwriteinformationaboutaparticularperson.
Contentprovidersarealsousefulforreadingandwritingdatathatisprivatetoyour
中北大学信息商务学院2015届毕业设计外文文献原文及译文
applicationandnotshared.Forexample,theNotePadsampleapplicationusesa
contentprovidertosavenotes.
AcontentproviderisimplementedasasubclassofContentProviderandmust
implementastandardsetofAPIsthatenableotherapplicationstoperform
transactions.Formoreinformation,seetheContentProvidersdeveloperguide.Broadcastreceivers
Abroadcastreceiverisacomponentthatrespondstosystem-widebroadcast
announcements.Manybroadcastsoriginatefromthesystem—forexample,a
broadcastannouncingthatthescreenhasturnedoff,thebatteryislow,orapicture
wascaptured.Applicationscanalsoinitiatebroadcasts—forexample,toletother
applicationsknowthatsomedatahasbeendownloadedtothedeviceandis
availableforthemtouse.Althoughbroadcastreceiversdon'tdisplayauser
interface,theymaycreateastatusbarnotificationtoalerttheuserwhenabroadcast
eventoccurs.Morecommonly,though,abroadcastreceiverisjusta"gateway"to
othercomponentsandisintendedtodoaveryminimalamountofwork.For
instance,itmightinitiateaservicetoperformsomeworkbasedontheevent.
AbroadcastreceiverisimplementedasasubclassofBroadcastReceiverandeach
broadcastisdeliveredasanIntentobject.Formoreinformation,see
theBroadcastReceiverclass.
AuniqueaspectoftheAndroidsystemdesignisthatanyapplicationcanstartanotherapplication’scomponent.Forexample,ifyouwanttheusertocaptureaphotowiththedevicecamera,there'sprobablyanotherapplicationthatdoesthatandyourapplicationcanuseit,insteadofdevelopinganactivitytocaptureaphotoyourself.Youdon'tneedtoincorporateorevenlinktothecodefromthecameraapplication.Instead,youcansimplystarttheactivityinthecameraapplicationthatcapturesaphoto.Whencomplete,thephotoisevenreturnedtoyourapplicationsoyoucanuseit.Totheuser,itseemsasifthecameraisactuallyapartofyourapplication.
中北大学信息商务学院2015届毕业设计外文文献原文及译文
Whenthesystemstartsacomponent,itstartstheprocessforthatapplication(ifit'snotalreadyrunning)andinstantiatestheclassesneededforthecomponent.Forexample,ifyourapplicationstartstheactivityinthecameraapplicationthatcapturesaphoto,thatactivityrunsintheprocessthatbelongstothecameraapplication,notinyourapplication'sprocess.Therefore,unlikeapplicationsonmostothersystems,Androidapplicationsdon'thaveasingleentrypoint(there'snomain()function,forexample).
Becausethesystemrunseachapplicationinaseparateprocesswithfilepermissionsthatrestrictaccesstootherapplications,yourapplicationcannotdirectlyactivateacomponentfromanotherapplication.TheAndroidsystem,however,can.So,toactivateacomponentinanotherapplication,youmustdeliveramessagetothesystemthatspecifiesyourintenttostartaparticularcomponent.Thesystemthenactivatesthecomponentforyou.
ActivatingComponents
Threeofthefourcomponenttypes—activities,services,andbroadcastreceivers—are
activatedbyanasynchronousmessagecalledanintent.Intentsbindindividualcomponents
toeachotheratruntime(youcanthinkofthemasthemessengersthatrequestanactionfromothercomponents),whetherthecomponentbelongstoyourapplicationoranother.
AnintentiscreatedwithanIntentobject,whichdefinesamessagetoactivateeitheraspecificcomponentoraspecifictypeofcomponent—anintentcanbeeitherexplicitor
implicit,respectively.
Foractivitiesandservices,anintentdefinestheactiontoperform(forexample,to"view"or"send"something)andmayspecifytheURIofthedatatoacton(amongotherthingsthatthecomponentbeingstartedmightneedtoknow).Forexample,anintentmightconveyarequestforanactivitytoshowanimageortoopenawebpage.Insomecases,youcanstartanactivitytoreceivearesult,inwhichcase,theactivityalsoreturnsth