外文翻译AndroidApplicationFundamentalsWord文档格式.docx
- 文档编号:20336353
- 上传时间:2023-01-22
- 格式:DOCX
- 页数:15
- 大小:30.65KB
外文翻译AndroidApplicationFundamentalsWord文档格式.docx
《外文翻译AndroidApplicationFundamentalsWord文档格式.docx》由会员分享,可在线阅读,更多相关《外文翻译AndroidApplicationFundamentalsWord文档格式.docx(15页珍藏版)》请在冰豆网上搜索。
∙Bydefault,thesystemassignseachapplicationauniqueLinuxuserID(theIDisusedonlybythesystemandisunknowntotheapplication).ThesystemsetspermissionsforallthefilesinanapplicationsothatonlytheuserIDassignedtothatapplicationcanaccessthem.
∙Eachprocesshasitsownvirtualmachine(VM),soanapplication'
scoderunsinisolationfromotherapplications.
∙Bydefault,everyapplicationrunsinitsownLinuxprocess.Androidstartstheprocesswhenanyoftheapplication'
scomponentsneedtobeexecuted,thenshutsdowntheprocesswhenit'
snolongerneededorwhenthesystemmustrecovermemoryforotherapplications.
Inthisway,theAndroidsystemimplementstheprincipleofleastprivilege.Thatis,eachapplication,bydefault,hasaccessonlytothecomponentsthatitrequirestodoitsworkandnomore.Thiscreatesaverysecureenvironmentinwhichanapplicationcannotaccesspartsofthesystemforwhichitisnotgivenpermission.
However,therearewaysforanapplicationtosharedatawithotherapplicationsandforanapplicationtoaccesssystemservices:
∙It'
spossibletoarrangefortwoapplicationstosharethesameLinuxuserID,inwhichcasetheyareabletoaccesseachother'
sfiles.Toconservesystemresources,applicationswiththesameuserIDcanalsoarrangetoruninthesameLinuxprocessandsharethesameVM(theapplicationsmustalsobesignedwiththesamecertificate).
∙Anapplicationcanrequestpermissiontoaccessdevicedatasuchastheuser'
scontacts,SMSmessages,themountablestorage(SDcard),camera,Bluetooth,andmore.Allapplicationpermissionsmustbegrantedbytheuseratinstalltime.
ThatcoversthebasicsregardinghowanAndroidapplicationexistswithinthesystem.Therestofthisdocumentintroducesyouto:
∙Thecoreframeworkcomponentsthatdefineyourapplication.
∙Themanifestfileinwhichyoudeclarecomponentsandrequireddevicefeaturesforyourapplication.
∙Resourcesthatareseparatefromtheapplicationcodeandallowyourapplicationtogracefullyoptimizeitsbehaviorforavarietyofdeviceconfigurations.
ApplicationComponents
ApplicationcomponentsaretheessentialbuildingblocksofanAndroidapplication.Eachcomponentisadifferentpointthroughwhichthesystemcanenteryourapplication.Notallcomponentsareactualentrypointsfortheuserandsomedependoneachother,buteachoneexistsasitsownentityandplaysaspecificrole—eachoneisauniquebuildingblockthathelpsdefineyourapplication'
soverallbehavior.
Therearefourdifferenttypesofapplicationcomponents.Eachtypeservesadistinctpurposeandhasadistinctlifecyclethatdefineshowthecomponentiscreatedanddestroyed.
Herearethefourtypesofapplicationcomponents:
Activities
Anactivityrepresentsasinglescreenwithauserinterface.Forexample,anemailapplicationmighthaveoneactivitythatshowsalistofnewemails,anotheractivitytocomposeanemail,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.
Contentprovidersarealsousefulforreadingandwritingdatathatisprivatetoyourapplicationandnotshared.Forexample,theNotePadsampleapplicationusesacontentprovidertosavenotes.
AcontentproviderisimplementedasasubclassofContentProviderandmustimplementastandardsetofAPIsthatenableotherapplicationstoperformtransactions.Formoreinformation,seetheContentProvidersdeveloperguide.
Broadcastreceivers
Abroadcastreceiverisacomponentthatrespondstosystem-widebroadcastannouncements.Manybroadcastsoriginatefromthesystem—forexample,abroadcastannouncingthatthescreenhasturnedoff,thebatteryislow,orapicturewascaptured.Applicationscanalsoinitiatebroadcasts—forexample,toletotherapplicationsknowthatsomedatahasbeendownloadedtothedeviceandisavailableforthemtouse.Althoughbroadcastreceiversdon'
tdisplayauserinterface,theymaycreateastatusbarnotificationtoalerttheuserwhenabroadcasteventoccurs.Morecommonly,though,abroadcastreceiverisjusta"
gateway"
toothercomponentsandisintendedtodoaveryminimalamountofwork.Forinstance,itmightinitiateaservicetoperformsomeworkbasedontheevent.
AbroadcastreceiverisimplementedasasubclassofBroadcastReceiverandeachbroadcastisdeliveredasanIntentobject.Formoreinformation,seetheBroadcastReceiverclass.
AuniqueaspectoftheAndroidsystemdesignisthatanyapplicationcanstartanotherapplication’scomponent.Forexample,ifyouwanttheusertocaptureaphotowiththedevicecamera,there'
sprobablyanotherapplicationthatdoesthatandyourapplicationcanuseit,insteadofdevelopinganactivitytocaptureaphotoyourself.Youdon'
tneedtoincorporateorevenlinktothecodefromthecameraapplication.Instead,youcansimplystarttheactivityinthecameraapplicationthatcapturesaphoto.Whencomplete,thephotoisevenreturnedtoyourapplicationsoyoucanuseit.Totheuser,itseemsasifthecameraisactuallyapartofyourapplication.
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—areactivatedbyanasynchronousmessagecalledanintent.Intentsbindindividualcomponentstoeachotheratruntime(youcanthinkofthemasthemessengersthatrequestanactionfromothercomponents),whetherthecomponentbelongstoyourapplicationoranother.
AnintentiscreatedwithanIntentobject,whichdefinesamessagetoactivateeitheraspecificcomponentoraspecifictypeofcomponent—anintentcanbeeitherexplicitorimplicit,respectively.
Foractivitiesandservices,anintentdefinestheactiontoperform(forexample,to"
view"
or"
send"
something)andmayspecifytheURIofthedatatoacton(amongotherthingsthatthecomponentbeingstartedmightneedtoknow).Forexample,anintentmightconveyarequestforanactivitytoshowanimageortoopenawebpage.Insomecases,youcanstartanactivitytoreceivearesult,inwhichcase,theactivityalsoreturnstheresultinanIntent(forexample,youcanissueanintenttolettheuserpickapersonalcontactandhaveitreturnedtoyou—thereturnintentincludesaURIpointingtothechosencontact).
Forbroadcastreceivers,theintentsimplydefinestheannouncementbeingbroadcast(forexample,abroadcasttoindicatethedevicebatteryislowincludesonlyaknownactionstringthatindicates"
batteryislow"
).
Theothercompon
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 外文 翻译 AndroidApplicationFundamentals