Android文档开发者指南第一部分入门中英文对照版word.docx
- 文档编号:18296061
- 上传时间:2023-08-15
- 格式:DOCX
- 页数:48
- 大小:61.03KB
Android文档开发者指南第一部分入门中英文对照版word.docx
《Android文档开发者指南第一部分入门中英文对照版word.docx》由会员分享,可在线阅读,更多相关《Android文档开发者指南第一部分入门中英文对照版word.docx(48页珍藏版)》请在冰点文库上搜索。
Android文档开发者指南第一部分入门中英文对照版word
一、Introduction(入门)
0、IntroductiontoAndroid(引进到Android)
AndroidprovidesarichapplicationframeworkthatallowsyoutobuildinnovativeappsandgamesformobiledevicesinaJavalanguageenvironment.ThedocumentslistedintheleftnavigationprovidedetailsabouthowtobuildappsusingAndroid'svariousAPIs.
Tolearnhowappswork,startwithAppFundamentals.
Tobegincodingrightaway,readBuildingYourFirstApp
Android提供了丰富的应用程序框架,它允许您在Java语言环境中构建移动设备的创新应用程序和游戏。
在左侧导航中列出的文档提供了有关如何使用Android的各种API来构建应用程序的详细信息。
要了解如何开发应用,从 应用基础开始。
如何开始一个正确的编码,请参照建立你的第一个应用程序。
Appsprovidemultipleentrypoints
应用程序提供多个入口点
Appsadapttodifferentdevices
应用程序适应不同的设备
Androidappsarebuiltasacombinationofdistinctcomponentsthatcanbeinvokedindividually.Forinstance,anindividual activity providesasinglescreenforauserinterface,anda serviceindependentlyperformsworkinthebackground.
Android应用程序被构建为能够单独地被调用不同的部件的组合。
例如,一个单独的Activity提供了一个单个屏幕上的用户界面,和一个Service独立地在后台中执行工作。
Androidprovidesanadaptiveappframeworkthatallowsyoutoprovideuniqueresourcesfordifferentdeviceconfigurations.Forexample,youcancreatedifferentXMLlayoutfilesfordifferentscreensizesandthesystemdetermineswhichlayouttoapplybasedonthecurrentdevice'sscreensize.
Android提供了一个自适应的应用程序框架,它允许您为不同的设备配置提供不同的资源。
例如,您可以为不同的屏幕尺寸创建不同的XML布局文件并且系统决定了基于当前屏幕尺寸使用哪些布局。
Fromonecomponentyoucanstartanothercomponentusingan intent.Youcanevenstartacomponentinadifferentapp,suchanactivityinamapsapptoshowanaddress.Thismodelprovidesmultipleentrypointsforasingleappandallowsanyapptobehaveasauser's"default"foranactionthatotherappsmayinvoke.
从一个组件就可以使用一个Intent启动另一个组件。
你甚至可以启动不同应用程序中的一个组件,比如启动一个地图应用中的Activity来显示地址。
该模型为一个单一的应用程序提供了多个入口点,并允许任何应用程序的行为作为用户的“默认”,用于其他应用程序调用的Action
Youcanquerytheavailabilityofdevicefeaturesatruntimeifanyappfeaturesrequirespecifichardwaresuchasacamera.Ifnecessary,youcanalsodeclarefeaturesyourapprequiressoappmarketssuchasGooglePlayStoredonotallowinstallationondevicesthatdonotsupportthatfeature.
你可以在运行时查询设备功能的可用性,如果任何应用程序的功能需要特定的硬件如照相机。
如果需要,你也可以定义你的应用程序需要的特性,,如GooglePlay商店不允许不支持该特性的设备安装。
Learnmore:
∙AppFundamentals
∙IntentsandIntentFilters
∙Activities
了解更多:
∙应用基础
∙意图和意图过滤器
∙Activities
Learnmore:
∙DeviceCompatibility
∙ResourcesOverview
∙UserInterfaceOverview
了解更多:
∙设备兼容性
∙资源概述
∙用户界面概述
1、ApplicationFundamentals(应用程序基础)
AndroidappsarewrittenintheJavaprogramminglanguage.TheAndroidSDKtoolscompileyourcode—alongwithanydataandresourcefiles—intoanAPK:
an Androidpackage,whichisanarchivefilewithan .apk suffix.OneAPKfilecontainsallthecontentsofanAndroidappandisthefilethatAndroid-powereddevicesusetoinstalltheapp.
Android应用程序是用Java写的。
AndroidSDK工具编译你的代码以及任何数据和资源文件为APK:
一个Android包,这是一个以.apk为后缀的存档文件。
一个APK文件包含了一个Android应用程序的所有内容,是Android平台的设备应用程序的安装文件。
Onceinstalledonadevice,eachAndroidapplivesinitsownsecuritysandbox:
一旦安装在设备上,每个Android应用程序存在于它自己的安全沙箱中:
INTHISDOCUMENT
AppComponents
Activatingcomponents
TheManifestFile
Declaringcomponents
Declaringcomponentcapabilities
Declaringapprequirements
AppResources
在本文档中
应用程序组件
激活组件
清单文件
声明组件
声明组件的能力
声明应用程序要求
应用程序资源
∙TheAndroidoperatingsystemisamulti-userLinuxsysteminwhicheachappisadifferentuser.
Android是一个多用户的Linux操作系统,每一个应用都是一个不同的用户。
∙Bydefault,thesystemassignseachappauniqueLinuxuserID(theIDisusedonlybythesystemandisunknowntotheapp).ThesystemsetspermissionsforallthefilesinanappsothatonlytheuserIDassignedtothatappcanaccessthem.
默认情况下,系统关联每一个应用程序到不同的Linux用户Id(这个ID只被系统使用,应用程序是不知道的)。
系统设置一个应用程序中的所有文件的权限,以便仅仅此应用程序的用户ID可以访问它们。
∙Eachprocesshasitsownvirtualmachine(VM),soanapp'scoderunsinisolationfromotherapps.
每一个进程都有他自己的虚拟机(VM),所以应用程序的代码的运行独立于其他应用程序。
∙Bydefault,everyapprunsinitsownLinuxprocess.Androidstartstheprocesswhenanyoftheapp'scomponentsneedtobeexecuted,thenshutsdowntheprocesswhenit'snolongerneededorwhenthesystemmustrecovermemoryforotherapps.
默认情况下,每一个应用程序运行在他自己的Linux进程。
当任何任用程序的祖先需要被执行的时候,Android启动这个程序的进程;当它不再需要时或系统必须恢复内存的其他应用程序,关闭该进程。
Inthisway,theAndroidsystemimplementsthe principleofleastprivilege.Thatis,eachapp,bydefault,hasaccessonlytothecomponentsthatitrequirestodoitsworkandnomore.Thiscreatesaverysecureenvironmentinwhichanappcannotaccesspartsofthesystemforwhichitisnotgivenpermission.
在这种方式中,Android系统实现了最小特权原则。
也就是说,每个应用程序,默认情况下,只能访问到它的工作所需要的最少的权限。
这将创建一个非常安全地环境:
每一个应用程序不能访问系统没有给予它权限的任何一个部分。
However,therearewaysforanapptosharedatawithotherappsandforanapptoaccesssystemservices:
然而,有办法让一个应用程序与其他应用程序共享数据,一个应用程序可以访问系统服务:
∙It'spossibletoarrangefortwoappstosharethesameLinuxuserID,inwhichcasetheyareabletoaccesseachother'sfiles.Toconservesystemresources,appswiththesameuserIDcanalsoarrangetoruninthesameLinuxprocessandsharethesameVM(theappsmustalsobesignedwiththesamecertificate).
它可以让两个应用程序共享相同的Linux用户ID,在这种情况下,他们能够访问对方的文件。
为了节省系统资源,应用程序使用相同的用户ID也可以运行在同一个Linux进程中,并共享相同的VM(并且应用程序也必须使用相同的证书签名)。
∙Anappcanrequestpermissiontoaccessdevicedatasuchastheuser'scontacts,SMSmessages,themountablestorage(SDcard),camera,Bluetooth,andmore.Allapppermissionsmustbegrantedbytheuseratinstalltime.
一个应用程序能够请求权限去访问设备上的数据,比如用户的联系人信息、短信、SDCard、照相机、蓝牙等等。
所有的应用程序权限必须在用户安装软件的时候给予授权。
ThatcoversthebasicsregardinghowanAndroidappexistswithinthesystem.Therestofthisdocumentintroducesyouto:
这包括关于一个Android应用程序怎样存在于系统中存在的基本知识。
本文档的其余部分向您介绍:
∙Thecoreframeworkcomponentsthatdefineyourapp.
定义您应用程序的的核心框架组件
∙Themanifestfileinwhichyoudeclarecomponentsandrequireddevicefeaturesforyourapp.
在您的应用程序Manifest文件中声明组件和所需设备功能
∙Resourcesthatareseparatefromtheappcodeandallowyourapptogracefullyoptimizeitsbehaviorforavarietyofdeviceconfigurations.
资源是独立于应用程序代码的,让你的应用程序,以优雅地行为为各种设备优化配置。
1.1、AppComponents(应用程序组件)
AppcomponentsaretheessentialbuildingblocksofanAndroidapp.Eachcomponentisadifferentpointthroughwhichthesystemcanenteryourapp.Notallcomponentsareactualentrypointsfortheuserandsomedependoneachother,buteachoneexistsasitsownentityandplaysaspecificrole—eachoneisauniquebuildingblockthathelpsdefineyourapp'soverallbehavior.
应用程序组件是一个Android应用程序的基本构造块。
每个组件都是一个不同的角度,通过该系统,可以进入你的应用程序。
不是所有的组件都是为用户和一些互相依赖的实际的切入点,但每一个都作为一个独立的的实体,扮演着特定的角色——每一个都是一个可以帮助确定您的应用程序的整体行为独特的构建快。
Therearefourdifferenttypesofappcomponents.Eachtypeservesadistinctpurposeandhasadistinctlifecyclethatdefineshowthecomponentiscreatedanddestroyed.
有四种不同类型的应用程序组件。
每种类型提供不同的目的,并具有明显的定义组件如何被创建和销毁的生命周期。
Herearethefourtypesofappcomponents:
以下是四种类型的应用程序组件:
Activity
An activity representsasinglescreenwithauserinterface.Forexample,anemailappmighthaveoneactivitythatshowsalistofnewemails,anotheractivitytocomposeanemail,andanotheractivityforreadingemails.Althoughtheactivitiesworktogethertoformacohesiveuserexperienceintheemailapp,eachoneisindependentoftheothers.Assuch,adifferentappcanstartanyoneoftheseactivities(iftheemailappallowsit).Forexample,acameraappcanstarttheactivityintheemailappthatcomposesnewmail,inorderfortheusertoshareapicture.
一个Activity表示为单个屏幕的用户界面。
比如,一个email应用程序可能用一个Activity显示新的email列表,用另一个Activity去写Activity,并且使用另外的Activity来阅读Email。
虽然活动一起形成一个有凝聚力的用户体验的电子邮件应用程序,但是每一个都是相互独立的。
同样的,不同的应用程序可以启动这些Activity中的任何一个(如果Email程序允许他这么做)。
比如所,一个相机应用为了分享一张照片可以启动一个Email应用中的Activity来创建一个新的Email。
Anactivityisimplementedasasubclassof Activity andyoucanlearnmoreaboutitinthe Activitiesdeveloperguide.
你的应用中的Activity应该是继承了Activity的一个子类,如果想要了解更多,可以参照Activities开发指南。
Service
A service isacomponentthatrunsinthebackgroundtoperformlong-runningoperationsortoperformworkforremoteprocesses.Aservicedoesnotprovideauserinterface.Forexample,aservicemightplaymusicinthebackgroundwhiletheuserisinadifferentapp,oritmightfetchdataoverthenetworkwithoutblockinguserinteractionwithanactivity.Anothercomponent,suchasanactivity,canstarttheserviceandletitrunorbindtoitinordertointeractwithit.
一个Service是一个运行在后台的、执行耗时操作或者执行跨进程操作的组件。
服务没有用户界面。
比如所,当用户在其他应用程序的时候,一个服务可能在后台播放音乐或者它可能从网络上读取数据但并不会阻塞用户和Activity交互。
另外一个组件,比如一个Activity,为了与Service交互,能够启动服务并且让它运行或者绑定到它。
Aserviceisimplementedasasubclassof Service andyoucanlearnmoreaboutitinthe Services developerguide.
你的应用中的Service应该是继承了Service的一个子类,如果你想了解更多,可以参照Services开发指南。
ContentProvider
A contentprovider managesasharedsetofappdata.Youcanstorethedatainthefilesystem,anSQLitedatabase,ontheweb,oranyotherpersistentstoragelocationyourappcanaccess.Throughthecontentprovider,otherappscanqueryorevenmodifythedata(ifthecontentproviderallowsit).Forexample,theAndroidsystemprovidesacontentproviderthatmanagestheuser'scontactinformation.Assuch,anyappwiththeproperpermissionscanquerypartofthecontentprovider(suchas ContactsContract.Data)toreadandwriteinformationaboutaparticularperson.
一个contentprovider管理一个分享数据的集合。
你能够存储数据到文件系统、SQLite数据库、在网络上或者任何其它的你能够访问的持久化存储位置。
通过ContentProvider,其他应用程序能够查询或者修改数据(如果ContentProvider允许它这么做)。
比如说,Android系统提供了一个管理用户联系人信息的ContentProvider。
同样的,任何具有适当权限的应用程序能够查询ContentProvider(比如ContactsContract.Data)去读取或者修改关于特定联系人的信息。
Contentprovidersarealsousefulforreadingandwritingdatathatisprivatetoyourappandnotshared.Forexample,the NotePad sampleappusesacontentprovi
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Android 文档 开发者 指南 第一 部分 入门 中英文 对照 word
![提示](https://static.bingdoc.com/images/bang_tan.gif)