版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
10英文文献原文:AndroidApplicationFundamentalsAndroidapplicationsarewrittenintheJavaprogramminglanguage.TheAndroidSDKtoolscompilethecode—alongwithanydataandresourcefiles—intoanAndroidpackage,anarchivefilewithan.apksuffix.Allthecodeinasingle.apkfileisconsideredtobeoneapplicationandisthefilethatAndroid-powereddevicesusetoinstalltheapplication.Onceinstalledonadevice,eachAndroidapplicationlivesinitsownsecuritysandbox:TheAndroidoperatingsystemisamulti-userLinuxsysteminwhicheachapplicationisadifferentuser.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.ApplicationComponentsApplicationcomponentsaretheessentialbuildingblocksofanAndroidapplication.Eachcomponentisadifferentpointthroughwhichthesystemcanenteryourapplication.Notallcomponentsareactualentrypointsfortheuserandsomedependoneachother,buteachoneexistsasitsownentityandplaysaspecificrole—eachoneisauniquebuildingblockthathelpsdefineyourapplication'soverallbehavior.Therearefourdifferenttypesofapplicationcomponents.Eachtypeservesadistinctpurposeandhasadistinctlifecyclethatdefineshowthecomponentiscreatedanddestroyed.Herearethefourtypesofapplicationcomponents:ActivitiesAnactivityrepresentsasinglescreenwithauserinterface.Forexample,anemailapplicationmighthaveoneactivitythatshowsalistofnewemails,anotheractivitytocomposeanemail,andanotheractivityforreadingemails.Althoughtheactivitiesworktogethertoformacohesiveuserexperienceintheemailapplication,eachoneisindependentoftheothers.Assuch,adifferentapplicationcanstartanyoneoftheseactivities(iftheemailapplicationallowsit).Forexample,acameraapplicationcanstarttheactivityintheemailapplicationthatcomposesnewmail,inorderfortheusertoshareapicture.AnactivityisimplementedasasubclassofActivityandyoucanlearnmoreaboutitintheActivitiesdeveloperguide.ServicesAserviceisacomponentthatrunsinthebackgroundtoperformlong-runningoperationsortoperformworkforremoteprocesses.Aservicedoesnotprovideauserinterface.Forexample,aservicemightplaymusicinthebackgroundwhiletheuserisinadifferentapplication,oritmightfetchdataoverthenetworkwithoutblockinguserinteractionwithanactivity.Anothercomponent,suchasanactivity,canstarttheserviceandletitrunorbindtoitinordertointeractwithit.AserviceisimplementedasasubclassofServiceandyoucanlearnmoreaboutitintheServicesdeveloperguide.ContentprovidersAcontentprovidermanagesasharedsetofapplicationdata.Youcanstorethedatainthefilesystem,anSQLitedatabase,ontheweb,oranyotherpersistentstoragelocationyourapplicationcanaccess.Throughthecontentprovider,otherapplicationscanqueryorevenmodifythedata(ifthecontentproviderallowsit).Forexample,theAndroidsystemprovidesacontentproviderthatmanagestheuser'scontactinformation.Assuch,anyapplicationwiththeproperpermissionscanquerypartofthecontentprovider(suchasContactsContract.Data)toreadandwriteinformationaboutaparticularperson.Contentprovidersarealsousefulforreadingandwritingdatathatisprivatetoyourapplicationandnotshared.Forexample,theNotePadsampleapplicationusesacontentprovidertosavenotes.AcontentproviderisimplementedasasubclassofContentProviderandmustimplementastandardsetofAPIsthatenableotherapplicationstoperformtransactions.Formoreinformation,seetheContentProvidersdeveloperguide.BroadcastreceiversAbroadcastreceiverisacomponentthatrespondstosystem-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.ActivatingComponentsThreeofthefourcomponenttypes—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").Theothercomponenttype,contentprovider,isnotactivatedbyintents.Rather,itisactivatedwhentargetedbyarequestfromaContentResolver.Thecontentresolverhandlesalldirecttransactionswiththecontentprovidersothatthecomponentthat'sperformingtransactionswiththeproviderdoesn'tneedtoandinsteadcallsmethodsontheContentResolverobject.Thisleavesalayerofabstractionbetweenthecontentproviderandthecomponentrequestinginformation(forsecurity).Thereareseparatemethodsforactivatingeachtypeofcomponent:Youcanstartanactivity(orgiveitsomethingnewtodo)bypassinganIntenttostartActivity()orstartActivityForResult()(whenyouwanttheactivitytoreturnaresult).Youcanstartaservice(orgivenewinstructionstoanongoingservice)bypassinganIntenttostartService().OryoucanbindtotheservicebypassinganIntenttobindService().YoucaninitiateabroadcastbypassinganIntenttomethodslikesendBroadcast(),sendOrderedBroadcast(),orsendStickyBroadcast().Youcanperformaquerytoacontentproviderbycallingquery()onaContentResolver.Formoreinformationaboutusingintents,seetheIntentsandIntentFiltersdocument.Moreinformationaboutactivatingspecificcomponentsisalsoprovidedinthefollowingdocuments:Activities,Services,BroadcastReceiverandContentProviders.中文翻译Android应用基础用Java编程语言编写的Android应用程序,被Android的SDK工具将它和数据以及资源文件编译到一个以.apk为后缀的Android程序包。在这个.apk文件的所有代码被认为是一个应用程序,并且是Android能够安装应用的程序。一旦应用程序被安装,每个Android应用程序的生命在它自己的访问权限:1.Android操作系统是一个多用户Linux系统,在它之上,每个应用程序是一个不同的用户。2.默认情况下,系统会分配给每个应用程序一个唯一的Linux用户ID(该ID仅用于由系统用使并不被应用程序所知),系统设置所有的应用程序中的文件访问权限,以便只有被分配用户ID的应用程序可以访问它们。3.每个进程都有它自己的虚拟机(VM),因此每个应用程序可以隔离其他应用程序而独立运行。4.默认情况下,每个应用程序运行它自己的Linux进程。当应用程序的任何组成部分需要被执行时,Android系统启动这个进程,然后当它不在被执行或系统必须为其它应用程序提供内存时,系统就关闭该进程。通过这种方式,Android系统实现了最小权限原则,也就是说默认情况下,每个应用程序只能访问需要工作的组部分。这将创建一个非常安全的环境,在其中,应用程序不能访问哪些对它没有权限的系统的部分。然而,还存在方法能够使应用程序分享其他应用程序的数据和访问系统服务进程:1.系统可以为两个应用程序安排相同的Linux用户ID,在这种情况下,它们能够相互访问对方的文件。为了节约系统资源,拥有相同ID的应用程序还可以被安排运行在相同的Linux进程中以及共享同一个虚拟机(应用程序也必须使用相同的证书签名)。2.应用程序可以请求设备数据的访问权限,如用户的联系人,短信,外部存储(SD卡),摄像头,蓝牙等设备的数据,所有应用程序的权限必须在用户在安装时被授予。关于Android应用程序如何在系统中存在的基本原理,文章的其余部分将向您介绍:1.框架核心组件:定义应用程序。2.程序声明文件:声明组件和应用程序所需的设备功能。3.资源文件:与程序代码分开并允许应用程序优化它的行为以应对各种的设备配置。应用程序组件(ApplicationComponents)应用程序组件是Android应用程序的核心模块之一。每一个组件都有不同的点,通过它系统能够进入你的应用程序。不是所有的组件都对用户有进入点,有一些依靠其他组件,但是每一个组件都有自己的实体和自己特殊的角色,每一个都是帮助定义应用程序行为的唯一模块。
这有四种应用程序组件,每一种都有特有的目的和定义、创建和关闭它的特有生命周期。如下:活动(Activities)一个
activity
代表用户界面的一个独立窗体。例如,一个邮件应用程序应该有一个activity用于显示新邮件列表,另一个activity用于撰写一封邮件,还有一个activity用于读取邮件。尽管所有activities协同工作以构成邮件应用程序的用户体验的实现,但彼此之间相对独立。由于这些,只要邮件应用程序允许,不同的应用程序能够启动任何一个activity。例如,用户需要分享一张照片,一个拍照应用程序能够启动邮件应用程序中撰写邮件的activity。activity是一个实现了
Activity
的子类,你可以在
Activities
开发者指导部分了解更多。服务(Services)service
是在后台运行的组件,它能够执行长时间操作或者执行远程操作。service不提供用户界面。例如,当用户在使用另一个应用程序时,一个service可在后台播放音乐,或者是从网络上获取数据,但却不影响用户与当前activity的交互。其他组件,比如一个activity,为了与该service交互,可以启动它使它运行或与它结合。service
是一个实现了Service
的子类,你可以在
Services
开发者指导部分了解更多。内容提供者(Contentproviders)内容提供者管理一系列共享的应用程序数据。这些数据可以存储于文件系统、SQLite数据库、互联网或其它的应用程序能够访问的持久存储的位置。通过contentprovider
,其他的应用程序能够查询甚至修改被它允许的数据。例如,Android系统提供一个contentprovider管理用户的联系信息。因此,任何拥有合适权限的应用程序可以查询内容提供者的部分数据如ContactsContract.Data来读取和写入一个特定的人的信息。内容提供商也用于对应用程序较私人和不共享阅读和写作数据。例如,记事本示例应用程序使用内容提供者保存笔记。contentprovider是ContentProvider的子类,它必须有一系列的APIs来确保其他的应用程序完成业务。有关更多信息,请参见内容提供者开发者指南。广播接收器(Broadcastreceivers)广播接收器是一个专注于接收广播通知信息,并做出对应处理的组件。很多广播是源自于系统,比如,通知屏幕关闭、电池电量低或拍摄了一张照片。应用程序也可以进行广播──比如说,通知其它应用程序一些数据下载完成并处于可用状态。虽然广播接收器没有用户界面,但是它们可以创建状态栏图标通知事件的发生。通常情况下,广播接收者对于其它的组件仅仅是一个“网关”,做非常少的工作。例如,它会根据事件启动一个服务组件来完成它。广播接收器是作为一个BroadcastReceiver子类,每一个广播接收器可以作为Intent对象被传递。更多信息,参阅BroadcastReceiver类。Android系统设计的一个独特方面是任何的一个程序都可以启动另一程序的组件。比如,你想让你的程序可以使用照相机拍照,如果已经有了实现这种功能的程序并且你的程序能使用它(有权限),那么你就没有再要再写一个新的Activity来实现这个功能。你不需要包含或者链接摄像头应用程序的代码。相反,你只需要在你的程序中打开这个拍照程序中的实现拍照功能的Activity。当拍完之后,拍好的照片甚至会自动返回给你的程序以便你能够使用。对于用户来说,就好像是拍照功能的程序就是你的这个程序的一部分一样。当系统启动一个组件之后,如果这个组件所在的程序之前没有运行的话,系统会自动开始这个程序的进程,并初始化这个组件所需要的相关类。比如,你的程序开启了一个拍照功能程序的Activity,这时系统会启动这个Activity所在的程序,所以这个Activity运行在拍照功能的程序当中,而不是在你的程序中。所以
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026湖北省定向中山大学选调生招录招聘考试笔试模拟试题及答案解析
- 2025中国人民大学人文社会科学部招聘2人考试笔试备考题库及答案解析
- 2025河南信阳潢川县社会保险中心招聘全日制公益性岗位4人笔试考试参考题库附答案解析
- 2025西安市中医医院招聘(2人)考试笔试参考题库附答案解析
- 企业服务创新方案
- 企业人力资源战略规划方案
- 2025北京市顺义区消防救援支队第四批政府专职消防员招录40人考试笔试模拟试题及答案解析
- 2025广东江门台山市医疗卫生单位招聘编外人员42人笔试考试备考题库及答案解析
- 2026湖北省定向哈尔滨工业大学选调生招录笔试考试备考试题及答案解析
- 2025北京广播电视台招聘200人考试笔试模拟试题及答案解析
- 2025年呼和浩特天骄航空有限公司招聘笔试冲刺题(带答案解析)
- 结直肠癌导致急性肠梗阻外科治疗中国专家共识(2025版)课件
- 辅助改方时方向继电器电路识读穆中华60课件
- 东方航空民航招飞面试常见问题及答案
- 危险性较大的分部分项工程清单
- 英语第二册(五年制高职) 课件 Unit5 Social Rules
- 银行物业年终工作总结
- 2025年三方询价单合同模板
- ISO14001-2015环境管理体系风险和机遇识别评价分析及应对措施表(包含气候变化)
- 如何正确书写化学方程式 教学设计
- 积极应对人口老龄化城市能力指数报告
评论
0/150
提交评论