基于android的微博客户端-外文翻译_第1页
基于android的微博客户端-外文翻译_第2页
基于android的微博客户端-外文翻译_第3页
基于android的微博客户端-外文翻译_第4页
基于android的微博客户端-外文翻译_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

0外文原文AndroidapplicationsarewrittenintheJavaprogramminglanguage.TheAndroidSDKtoolscompilethecodealongwithanydataandresourcefilesintoanAndroidpackage,anarchivefilewithan.apksuffix.Allthecodeinasingle.apkfileisconsideredtobeoneapplicationandisthefilethatAndroid-powereddevicesusetoinstalltheapplication.Anapplicationcanrequestpermissiontoaccessdevicedatasuchastheuserscontacts,SMSmessages,themountablestorage(SDcard),camera,Bluetooth,andmore.ApplicationComponentsApplicationcomponentsaretheessentialbuildingblocksofanAndroidapplication.Eachcomponentisadifferentpointthroughwhichthesystemcanenteryourapplication.Notallcomponentsareactualentrypointsfortheuserandsomedependoneachother,buteachoneexistsasitsownentityandplaysaspecificroleeachoneisauniquebuildingblockthathelpsdefineyourapplicationsoverallbehavior.Therearefourdifferenttypesofapplicationcomponents.Eachtypeservesadistinctpurposeandhasadistinctlifecyclethatdefineshowthecomponentiscreatedanddestroyed.Herearethefourtypesofapplicationcomponents:ActivitiesAnactivityrepresentsasinglescreenwithauserinterface.Forexample,anemailapplicationmighthaveoneactivitythatshowsalistofnewemails,anotheractivitytocomposeanemail,andanotheractivityforreadingemails.Althoughtheactivitiesworktogethertoformacohesiveuserexperienceintheemailapplication,eachoneisindependentoftheothers.Assuch,adifferentapplicationcanstartanyoneoftheseactivities(iftheemailapplicationallowsit).Forexample,acameraapplicationcanstarttheactivityintheemailapplicationthatcomposesnewmail,inorderfortheusertoshareapicture.AnactivityisimplementedasasubclassofActivityandyoucanlearnmoreaboutitintheActivitiesdeveloperguideServices1Aserviceisacomponentthatrunsinthebackgroundtoperformlong-runningoperationsortoperformworkforremoteprocesses.Aservicedoesnotprovideauserinterface.Forexample,aservicemightplaymusicinthebackgroundwhiletheuserisinadifferentapplication,oritmightfetchdataoverthenetworkwithoutblockinguserinteractionwithanactivity.Anothercomponent,suchasanactivity,canstarttheserviceandletitrunorbindtoitinordertointeractwithit.AserviceisimplementedasasubclassofServiceandyoucanlearnmoreaboutitintheServicesdeveloperguide.ContentprovidersAcontentprovidermanagesasharedsetofapplicationdata.Youcanstorethedatainthefilesystem,anSQLitedatabase,ontheweb,oranyotherpersistentstoragelocationyourapplicationcanaccess.Throughthecontentprovider,otherapplicationscanqueryorevenmodifythedata(ifthecontentproviderallowsit).Forexample,theAndroidsystemprovidesacontentproviderthatmanagestheuserscontactinformation.Assuch,anyapplicationwiththeproperpermissionscanquerypartofthecontentprovider(suchasContactsContract.Data)toreadandwriteinformationaboutaparticularperson.Contentprovidersarealsousefulforreadingandwritingdatathatisprivatetoyourapplicationandnotshared.Forexample,theNotePadsampleapplicationusesacontentprovidertosavenotes.AcontentproviderisimplementedasasubclassofContentProviderandmustimplementastandardsetofAPIsthatenableotherapplicationstoperformtransactions.Formoreinformation,seetheContentProvidersdeveloperguide.broadcastreceiverAbroadcastreceiverisacomponentthatrespondstosystem-widebroadcastannouncements.Manybroadcastsoriginatefromthesystemforexample,abroadcastannouncingthatthescreenhasturnedoff,thebatteryislow,orapicturewascaptured.Applicationscanalsoinitiatebroadcastsforexample,toletotherapplicationsknowthatsomedatahasbeendownloadedtothedeviceandisavailableforthemtouse.Althoughbroadcastreceiversdontdisplayauserinterface,theymaycreateastatusbarnotificationto2alerttheuserwhenabroadcasteventoccurs.Morecommonly,though,abroadcastreceiverisjustagatewaytoothercomponentsandisintendedtodoaveryminimalamountofwork.Forinstance,itmightinitiateaservicetoperformsomeworkbasedontheevent.AbroadcastreceiverisimplementedasasubclassofBroadcastReceiverandeachbroadcastisdeliveredasanIntentobject.Formoreinformation,seetheBroadcastReceiverclass.AuniqueaspectoftheAndroidsystemdesignisthatanyapplicationcanstartanotherapplicationscomponent.Forexample,ifyouwanttheusertocaptureaphotowiththedevicecamera,theresprobablyanotherapplicationthatdoesthatandyourapplicationcanuseit,insteadofdevelopinganactivitytocaptureaphotoyourself.Youdontneedtoincorporateorevenlinktothecodefromthecameraapplication.Instead,youcansimplystarttheactivityinthecameraapplicationthatcapturesaphoto.Whencomplete,thephotoisevenreturnedtoyourapplicationsoyoucanuseit.Totheuser,itseemsasifthecameraisactuallyapartofyourapplication.Whenthesystemstartsacomponent,itstartstheprocessforthatapplication(ifitsnotalreadyrunning)andinstantiatestheclassesneededforthecomponent.Forexample,ifyourapplicationstartstheactivityinthecameraapplicationthatcapturesaphoto,thatactivityrunsintheprocessthatbelongstothecameraapplication,notinyourapplicationsprocess.Therefore,unlikeapplicationsonmostothersystems,Androidapplicationsdonthaveasingleentrypoint(theresnomain()function,forexample).Becausethesystemrunseachapplicationinaseparateprocesswithfilepermissionsthatrestrictaccesstootherapplications,yourapplicationcannotdirectlyactivateacomponentfromanotherapplication.TheAndroidsystem,however,can.So,toactivateacomponentinanotherapplication,youmustdeliveramessagetothesystemthatspecifiesyourintenttostartaparticularcomponent.Thesystemthenactivatesthecomponentforyou.ActivatingComponentsThreeofthefourcomponenttypesactivities,services,andbroadcastreceiversareactivatedbyanasynchronousmessagecalledanintent.Intentsbindindividualcomponentstoeachotheratruntime(youcanthinkofthemasthemessengersthat3requestanactionfromothercomponents),whetherthecomponentbelongstoyourapplicationoranother.AnintentiscreatedwithanIntentobject,whichdefinesamessagetoactivateeitheraspecificcomponentoraspecifictypeofcomponentanintentcanbeeitherexplicitorimplicit,respectivelyForactivitiesandservices,anintentdefinestheactiontoperform(forexample,tovieworsendsomething)andmayspecifytheURIofthedatatoacton(amongotherthingsthatthecomponentbeingstartedmightneedtoknow).Forexample,anintentmightconveyarequestforanactivitytoshowanimageortoopenawebpage.Insomecases,youcanstartanactivitytoreceivearesult,inwhichcase,theactivityalsoreturnstheresultinanIntent(forexample,youcanissueanintenttolettheuserpickapersonalcontactandhaveitreturnedtoyouthereturnintentincludesaURIpointingtothechosencontact).Forbroadcastreceivers,theintentsimplydefinestheannouncementbeingbroadcast(forexample,abroadcasttoindicatethedevicebatteryislowincludesonlyaknownactionstringthatindicatesbatteryislow).Theothercomponenttype,contentprovider,isnotactivatedbyintents.Rather,itisactivatedwhentargetedbyarequestfromaContentResolver.ThecontentresolverhandlesalldirecttransactionswiththecontentprovidersothatthecomponentthatsperformingtransactionswiththeproviderdoesntneedtoandinsteadcallsmethodsontheContentResolverobject.Thisleavesalayerofabstractionbetweenthecontentproviderandthecomponentrequestinginformation(forsecurity).ThereareseparatemethodsforactivatingeachtypeofcomponentYoucanstartanactivity(orgiveitsomethingnewtodo)bypassinganIntenttostartActivity()orstartActivityForResult()(whenyouwanttheactivitytoreturnaresult).Youcanstartaservice(orgivenewinstructionstoanongoingservice)bypassinganIntenttostartService().OryoucanbindtotheservicebypassinganIntenttobindService().YoucaninitiateabroadcastbypassinganIntenttomethodslikesendBroadcast(),sendOrderedBroadcast(),orsendStickyBroadcast().4Youcanperformaquerytoacontentproviderbycallingquery()onaContentResolver.Formoreinformationaboutusingintents,seetheIntentsandIntentFiltersdocument.Moreinformationaboutactivatingspecificcomponentsisalsoprovidedinthefollowingdocuments:Activities,Services,BroadcastReceiverandContentProviders.DeclaringcomponentsTheprimarytaskofthemanifestistoinformthesystemabouttheapplicationscomponents.Forexample,amanifestfilecandeclareanactivityasfollows:Intheelement,theandroid:iconattributepointstoresourcesforaniconthatidentifiestheapplication.Intheelement,theandroid:nameattributespecifiesthefullyqualifiedclassnameoftheActivitysubclassandtheandroid:labelattributesspecifiesastringtouseastheuser-visiblelabelfortheactivity.Youmustdeclareallapplicationcomponentsthisway:elementsforactivitieselementsforserviceselementsforbroadcastreceiverselementsforcontentprovidersActivities,services,andcontentprovidersthatyouincludeinyoursourcebutdonotdeclareinthemanifestarenotvisibletothesystemand,consequently,canneverrun.However,broadcastreceiverscanbeeitherdeclaredinthemanifestorcreateddynamicallyincode(asBroadcastReceiverobjects)andregisteredwiththesystembycallingregisterReceiver().DeclaringcomponentcapabilitiesAsdiscussedabove,inActivatingComponents,youcanuseanIntenttostartactivities,services,andbroadcastreceivers.Youcandosobyexplicitlynamingthetargetcomponent(usingthecomponentclassname)intheintent.However,therealpowerofintentsliesintheconceptofintentactions.Withintentactions,yousimplydescribethetypeofactionyouwanttoperform(andoptionally,thedatauponwhichyoudliketoperformtheaction)andallowthesystemtofindacomponentonthedevicethatcanperformtheactionandstartit.Iftherearemultiplecomponentsthatcanperformtheactiondescribedbytheintent,thentheuserselectswhichonetouse.Thewaythesystemidentifiesthecomponentsthatcanrespondtoanintentisbycomparingtheintentreceivedtotheintentfiltersprovidedinthemanifest5fileofotherapplicationsonthedevice.Whenyoudeclareacomponentinyourapplicationsmanifest,youcanoptionallyincludeintentfiltersthatdeclarethecapabilitiesofthecomponentsoitcanrespondtointentsfromotherapplications.Youcandeclareanintentfilterforyourcomponentbyaddinganelementasachildofthecomponentsdeclarationelement.Forexample,anemailapplicationwithanactivityforcomposinganewemailmightdeclareanintentfilterinitsmanifestentrytorespondtosendintents(inordertosendemail).Anactivityinyourapplicationcanthencreateanintentwiththe“send”action(ACTION_SEND),whichthesystemmatchestotheemailapplications“send”activityandlaunchesitwhenyouinvoketheintentwithstartActivity().Formoreaboutcreatingintentfilters,seetheIntentsandIntentFiltersdocument.DeclaringapplicationrequirementsThereareavarietyofdevicespoweredbyAndroidandnotallofthemprovidethesamefeaturesandcapabilities.Inordertopreventyourapplicationfrombeinginstalledondevicesthatlackfeaturesneededbyyourapplication,itsimportantthatyouclearlydefineaprofileforthetypesofdevicesyourapplicationsupportsbydeclaringdeviceandsoftwarerequirementsinyourmanifestfile.Mostofthesedeclarationsareinformationalonlyandthesystemdoesnotreadthem,butexternalservicessuchasGooglePlaydoreadtheminordertoprovidefilteringforuserswhentheysearchforapplicationsfromtheirdevice.Forexample,ifyourapplicationrequiresacameraandusesAPIsintroducedinAndroid2.1(APILevel7),youshoulddeclaretheseasrequirementsinyourmanifestfile.Thatway,devicesthatdonothaveacameraandhaveanAndroidversionlowerthan2.1cannotinstallyourapplicationfromGooglePlay.InputconfigurationsManydevicesprovideadifferenttypeofuserinputmechanism,suchasahardwarekeyboard,atrackball,orafive-waynavigationpad.Ifyourapplicationrequiresaparticularkindofinputhardware,thenyoushoulddeclareitinyourmanifestwiththeelement.However,itisrarethatanapplicationshouldrequireacertaininputconfiguration.6DevicefeaturesTherearemanyhardwareandsoftwarefeaturesthatmayormaynotexistonagivenAndroid-powereddevice,suchasacamera,alightsensor,bluetooth,acertainversionofOpenGL,orthefidelityofthetouchscreen.YoushouldneverassumethatacertainfeatureisavailableonallAndroid-powereddevices(otherthantheavailabilityofthestandardAndroidlibrary),soyoushoulddeclareanyfeaturesusedbyyourapplicationwiththeelement.外文翻译7Android应用程序是用Java编程语言编写的。AndroidSDK工具编译code-along任何数据和资源files-intoAndroid包,和一个存档文件。apk后缀。在一个单一的所有代码。apk文件被认为是一个应用程序,android设备使用的文件安装应用程序。应用程序可以请求访问设备数据,如用户的联系人、短信、挂载存储(SD卡),相机,蓝牙,和更多。应用程序组件应用程序组件是Android应用程序的基本构建块。每个组件是一个不同的点,系统可以通过输入您的应用程序。并不是所有的组件都实际为用户入口点和一些相互依赖,但每一个作为自己的实体存在,扮演一个特定role-each是一个独特的构建块,可以帮助定义应用程序的整体行为。有四种不同类型的应用程序组件。每种类型都有不同的目的,不同的生命周期,它定义了如何创建和销毁组件。这里有四种类型的应用程序组件:活动一个活动代表一个单一的用户界面屏幕。例如,一个电子邮件应用程序可能有一个活动,展示了一个新邮件列表,另一个活动来撰写电子邮件,阅读电子邮件,另一个活动。虽然活动共同形成一个有凝聚力的用户体验在电子邮件应用程序中,每一个都是相互独立的。因此,一个不同的应用程序可以启动任何一个这些活动(如果电子邮件应用程序允许它)。例如,摄像机应用程序可以启动活动在电子邮件应用程序,组成新邮件,为了用户分享照片。一个活动被实现为一个活动,你可以了解更多关于它的子类的活动开发人员指南。服务服务是一个在后台运行的组件来执行长期操作或执行工作为远程过程。服务不提供用户界面。例如,一个服务可能在后台播放音乐时,在不同的应用程序中,用户也可以通过网络获取数据没有阻止用户交互活动。另一个组件,比如活动,可以开始服务,让它运行或绑定到它来与之交互。服务是作为一个子类实现的服务,您可以了解更多关于服务开发者指南。内容提供者内容提供者一个内容提供者管理一组共享的应用程序数据。您可以将数据存储在文件系统中,一个SQLite数据库,在网上,或任何其他应用程序可以访问持久性存储位置。通过内容提供者,其他应用程序可以查询或者修改数据(如果内容提供者允许)。例如,Android系统提供了一个内容提供者,管理用户的联系信息。因此,任何应用程序的权限可以查询的一部分内容提供商(比如ContactsContract.Data)读写一个特定的人的信息。对于阅读和写作内容提供商也有用私人到您的应用程序的数据,不能共享。例如,记事本示例应用程序使用一个内容提供商保存笔记。一个内容提供者ContentProvider和被实现为一个子类必须实现一组标准的api,允许其他应用程序执行事务。有关更多信息,请参见内容提供商开发人员指南。广播接收器广播接收器是一个组件,响应系统广播公告。许多广播由系统发起比如,一个广播宣布屏幕已关闭,电池低,或者照片被捕获。应用程序也可以初始化广播比如,让其他应用程序知道一些数据已经被下载到设备上,可以被使用。虽然广播接收器不显示一个用户界面,他们可能会创建一个状态栏通知提醒用户当广播事件发生时。更常见的,一个广播接收器只是一个“网关”其他组件和旨在做最少的工作。例如,它可以启动一个服务来执行基于事件的一些工作。广播接收器被实现为一个子类8BroadcastReceiver和每个广播作为一个意图对象。有关更多信息,请参见theBroadcastReceiver类。安卓系统设计的一个独特的方面是,任何应用程序都可以启动另一个应用程序的组件。例如,如果您希望用户捕捉一张照片与设备摄像头,可能另一个应用程序,这是否和您的应用程序可以使用它,而不是发展一个活动来捕捉一张照片你自己。你不需要协同甚至连相机应用程序的代码。相反,您可以简单地启动相机应用程序捕获的活动照片。完成后,照片甚至回到您的应用程序,您可以使用它。对于用户而言,好像镜头实际上是一个应用程序的一部分。当系统启动一个组件,它开始的过程,应用程序(如果不是已经运行)并实例化类所需的组件。例如,如果您的应用程序启动相机应用程序捕捉照片的活动,活动运行的过程,属于相机应用程序,而不是在您的应用程序的过程。因此,在大多数其他系统与应用程序,Android应用程序没有一个单一的入口点(没有主要()函数,例如)。每个应用程序因为系统运行在一个单独的流程与文件权限限制访问其他应用程序,应用程序不能直接激活另一个应用程序的组件。然而,Android系统。激活一个组件在另一个应用程序,您必须提供一个信息系统,指定你的意图开始一个特定的组件。然后系统为你激活的组件。激活的组件三四个组件的types-activities、服务和广播receivers-are激活通过异步消息称为一个意图。意图将各个组件绑定到彼此在运行时(你可以把它们作为使者,请求一个行动从其他组件),组件是否属于您的应用程序或另一个。目的是创建一个意图对象,定义了一个消息激活特定的组件或特定类型的intent可以显式或隐式的,的活动和服务,一个意图定义了动作执行(例如,“视图”或“发送”的东西),可能指定的URI数据采取行动(除此之外的组件开始可能需要知道)。例如,一个可能传达意图,请求一个活动显示一个图像或打开一个网页。在某些情况下,您可以启动一个活动获得的结果,在这种情况下,意图的活动也返回结果(例如,您可以发出有意让用户选择一个个人接触和它回到你返回意图包括一个URI指向选择接触)。广播接收器,目的简单地定义了消息被广播(例如,一个指示设备电池是低的广播只包含一个已知的操作字符串,表示“电池是低”)。另一个组件类型,内容提供商,不是激活的意图。相反,它是从ContentResolver激活时的目标要求。内容解析器处理所有与内容提供者直接交易,这样的组件与提供者不需要执行交易,而是调用方法ContentResolver对象。这使得一个抽象层之间的内容提供者和组件请求信息(安全)。有单独的方法激活每种类型的组件:你可以开始一个活动(或给它一些新的东西)通过一个意图startActivity()或startActivityForResult()(当您想要返回一个结果)的活动。您可以启动一个服

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论