当前位置: 网学 > 编程文档 > Android > 正文

英文翻译资料原文及译文android方面

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: myeducs.cn 发布时间: 13/03/17

【网学网提醒】:网学会员编辑为广大网友搜集整理了:英文翻译资料原文及译文android方面绩等信息,祝愿广大网友取得需要的信息,参考学习


    AndroidApplicationFundamentals
    AndroidapplicationsarewrittenintheJavaprogramminglanguage.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:1、Thecoreframeworkcomponentsthatdefineyourapplication.2、Themanifestfileinwhichyoudeclarecomponentsandrequireddevicefeaturesforyourapplication.3、Resourcesthatareseparatefromtheapplicationcodeandallowyourapplicationtogracefullyoptimizeitsbehaviorforavarietyofdeviceconfigurations.
    ApplicationComponents
    ApplicationcomponentsaretheessentialbuildingblocksofanAndroidapplication.Eachcomponentisadifferentpointthroughwhichthesystemcanenteryourapplication.Notallcomponentsarea
    ctualentrypointsfortheuserandsomedependoneachother,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.For共21页第1页
     合肥大学毕业论文
    example,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
    Abroadcastreceiverisacomponentt
    hatrespondstosystem-widebroadcastannouncements.Manybroadcastsoriginatefromthesystem—forexample,abroadcastannouncingthatthescreenhasturnedoff,thebatteryislow,orapicturewascaptured.Applicationscanalsoinitiatebroadcasts—forexample,toletotherapplicationsknowthatsomedatahasbeendownloadedtothedeviceandisavailableforthemtouse.Althoughbroadcastreceiversdon'tdisplayauserinterface,theymaycreateastatusbarnotificationtoalerttheuserwhenabroadcasteventoccurs.Morecommonly,though,abroadcastreceiverisjusta"gateway"toothercomponentsandisintendedtodoaveryminimalamountofwork.Forinstance,itmightinitiateaservicetoperformsomeworkbasedontheevent.共21页第2页
     合肥大学毕业论文
    AbroadcastreceiverisimplementedasasubclassofBroadcastReceiverandeachbroadcastisdeliveredasanIntentobject.Formoreinformation,see
    theBroadcastReceiverclass.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),whetherthecomponentbelongstoyourapplicationor
    another.
    共
    21
    页
    第
    3
    页
     合肥大学毕业论文
    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.
    共
    21
    页
    第
    4
    页
     合肥大学毕业论文
    Formoreinformationaboutusingintents,seetheIntentsandIntentFiltersdocument.Moreinformationaboutactivatingspecificcomponentsisalsoprovidedinthefollowingdocuments:Activities,Services,BroadcastReceiverandContentProviders.
    Declaringcomponents
    Theprimarytaskofthemanifestistoinformthesystemabouttheapplication'scomponents.Forexample,amanifestfilecandeclareanactivityasfollows:
    ...    n>
    Intheelement,theandroid:iconattributepointstoresourcesforaniconthatidentifiestheapplication.Intheelement,theandroid:nameattributespecifiesthefullyqualifiedclassnameoftheActivitysubclassandtheandroid:labelattributesspecifiesastringtouseastheuser-visiblelabelfortheactivity.Youmustdeclareallapplicationcomponentsthisway:1、elementsforactivities2、elementsforservices3、elementsforbroadcastreceivers4、elementsforcontentprovidersActivities,services,andcontentprovidersthatyouincludeinyoursourcebutdonotdeclareinthemanifestarenotvisibletothesystemand,consequently,canneverrun.共21页第5页
     合肥大学毕业论文
    However,broadcastreceiverscanbeeitherdeclaredinthemanifestorcreateddynamicallyincode(asBroadcastReceiverobjects)andregisteredwiththesystembycallingregisterReceiver().
    Declaringcomponentcapabilities
    Asdiscussedabove,inActivatingComponents,youcanuseanIntenttostartactivities,services,andbroadcastreceivers.Youcandosobyexplicitlynamingthetargetcomponent(usingthecomponentclassname)intheintent.However,therealpowerofintentsliesintheconceptofintentactions.Withintentactions,yousimplydescribethetypeofactionyouwanttoperform(andoptionally,thedatauponwhichyou’dliketoperformtheaction)andallowthesystemtofindacomponentonthedevicethatcanperformtheactionandstartit.Iftherearemultiplecomponentsthatcanperformtheactiondescribedbytheintent,thentheuserselectswhichonetouse.Thewaythesystemidentifiesthecomponentsthatcanrespondtoanintentisbycomparingtheintentreceivedtotheintentfiltersprovidedinthemanifestfileofotherapplicationsonthedevice.Whenyoudeclareacomponentinyourapplication'smanifest,youcanoptionallyincludeintentfiltersthatdeclarethecapabilitiesofthecomponentsoitcanrespondtointentsfromotherapplications.Youcandeclareanintentfilterforyourcomponentbyaddinganelementasachildofthecomponent'sdeclarationelement.Forexample,anemailapplicationwithanactivityforcomposinganewemailmightdeclareanintentfilterinitsmanifestentrytorespondto"send"intents(inordertosendemail).Anactivityinyourapplicationcanthencreateanintentwiththe“send”action(ACTION_SEND),whichthesystemmatchestotheemailapplication’s“send”activityandlaunchesitwhenyouinvoketheintentwithstartActivity().Formoreaboutcreatingintentfilters,seetheIntentsandIntentFiltersdocument.
    Declaringapplicationrequirements
    ThereareavarietyofdevicespoweredbyAndroidandnotallofthemprovidethesamefeaturesandcapabilities.Inordertopreventyourapplicationfrombeinginstalledondevices共21页
    第6页
     合肥大学毕业论文
    thatlackfeaturesneededbyyourapplication,it'simportantthatyouclearlydefineaprofileforthetypesofdevicesyourapplicationsupportsbydeclaringdeviceandsoftwarerequirementsinyourmanifestfile.Mostofthesedeclarationsareinformationalonlyandthesystemdoesnotreadthem,butexternalservicessuchasGooglePlaydoreadtheminordertoprovidefilteringforuserswhentheysearchforapplicationsfromtheirdevice.Forexample,ifyourapplicationrequiresacameraandusesAPIsintroducedinAndroid2.1(APILevel7),youshoulddeclaretheseasrequirementsinyourmanifestfile.Thatway,devicesthatdonothaveacameraandhaveanAndroidversionlowerthan2.1cannotinstallyourapplicationfromGooglePlay.However,youcanalsodeclarethatyourapplicationusesthecamera,butdoesnotrequireit.Inthatcase,yourapplicationmustperformacheckatruntimetodetermineifthedevicehasacameraanddisableanyfeaturesthatusethecameraifoneisnotavailable.Herearesomeoftheimportantdevicecharacteristicsthatyoushouldconsiderasyoudesignanddevelopyourapplication:ScreensizeanddensityInordertocategorizedevicesbytheirscreentype,Androiddefinestwocharacteristicsforeachdevice:screensize(thephysicaldimensionsofthescreen)andscreendensity(thephysicaldensityofthepixelsonthescreen,ordpi—dotsperinch).Tosimplifyallthedifferenttypesofscreenconfigurations,theAndroidsystemgeneralizesthemintoselectgroupsthatmakethemeasiertotarget.
    Thescreensizesare:small,normal,large,andextralarge.Thescreendensitiesare:lowdensity,mediumdensity,highdensity,andextrahighdensity.Bydefault,yourapplicationiscompatiblewithallscreensizesanddensities,becausetheAndroidsystemmakestheappropriateadjustmentstoyourUIlayoutandimageresources.However,youshouldcreatespecializedlayoutsforcertainscreensizesandprovidespecializedimagesforcertaindensities,usingalternativelayoutresources,andbydeclaringinyourmanifestexactlywhichscreensizesyourapplicationsupportswiththeelement.
    共
    21
    页
    第
    7
    页
     合肥大学毕业论文
    Formoreinformation,seetheSupportingMultipleScreensdocument.InputconfigurationsManydevicesprovideadifferenttypeofuserinputmechanism,suchasahardwarekeyboard,atrackball,orafive-waynavigationpad.Ifyourapplicationrequiresaparticularkindofinputhardware,thenyoushoulddeclareitinyourmanifestwith
    theelement.However,itisrarethatanapplicationshouldrequireacertaininputconfiguration.DevicefeaturesTherearemanyhardwareandsoftwarefeaturesthatmayormaynotexistonagivenAndroid-powereddevice,suchasacamera,alightsensor,bluetooth,acertainversionofOpenGL,orthefidelityofthetouchscreen.Yousho
    uldneverassumethatacertainfeatureisavailableonallAndroid-powereddevices(otherthantheavailabilityofthestandardAndroidlibrary),soyoushoulddeclareanyfeaturesusedbyyourapplicationwith
    theelement.PlatformVersionDifferentAndroid-powereddevicesoftenrundifferentversionsoftheAndroidplatform,suchasAndroid1.6orAndroid2.3.EachsuccessiveversionoftenincludesadditionalAPIsnotavailableinthepreviousversion.InordertoindicatewhichsetofAPIsareavailable,eachplatformversionspecifiesanAPILevel(forexample,Android1.0isAPILevel1andAndroid2.3isAPILevel9).IfyouuseanyAPIsthatwereaddedtotheplatformafterversion1.0,youshoulddeclaretheminimumAPILevelinwhichthoseAPIswereintroducedusingtheelement.It'simportantthatyoudeclareallsuchrequirementsforyourapplication,because,whenyoudistributeyourapplicationonGooglePlay,thestoreusesthesedeclarationstofilterwhichapplicationsareavailableoneachdevice.Assuch,yourapplicationshouldbeavailableonlytodevicesthatmeetallyourapplicationrequirements.FormoreinformationabouthowGooglePlayfiltersapplicationsbasedonthese(andother)requirements,seetheFiltersonGooglePlaydocument.
    ApplicationResources
    共
    21
    页
    第
    8
    页
     合肥大学毕业论文
    AnAndroidapplicationiscomposedofmorethanjustcode—itrequiresresourcesthatareseparatefromthesourcecode,suchasimages,audiofiles,andanythingrelatingtothevisualpresentationoftheapplication.Forexample,youshoulddefineanimations,menus,styles,colors,andthelayoutofactivityuserinterfaceswithXMLfiles.Usingapplicationresourcesmakesiteasytoupdatevariouscharacteristicsofyourapplicationwithoutmodifyingcodeand—byprovidingsetsofalternativeresources—enablesyoutooptimizeyourapplicationforavarietyofdeviceconfigurations(suchasdifferentlanguagesandscreensizes).ForeveryresourcethatyouincludeinyourAndroidproject,theSDKbuildtoolsdefineauniqueintegerID,whichyoucanusetoreferencetheresourcefromyourapplicationcodeorfromotherresourcesdefinedinXML.Forexample,ifyourapplicationcontainsanimagefilenamedlogo.png(savedintheres/drawable/directory),theSDKtoolsgeneratearesourceIDnamedR.drawable.logo,whichyoucanusetoreferencetheimageandinsertitinyouruserinterface.Oneofthemostimportantaspectsofprovidingresourcesseparatefromyoursourcecodeistheabilityforyoutoprovidealternativeresourcesfordifferentdeviceconfigurations.Forexample,bydefiningUIstringsinXML,youcantranslatethestringsintootherlanguagesandsavethosestringsinseparatefiles.Then,basedonalanguagequalifierthatyouappendtotheresourcedirectory'sname(suchasres/values-fr/forFrenchstringvalues)andtheuser'slanguagesetting,theAn
    droidsystemappliestheappropriatelanguagestringstoyourUI.Androidsupportsmanydifferentqualifiersforyouralternativeresources.Thequalifierisashortstringthatyouincludeinthenameofyourresourcedirectoriesinordertodefinethedeviceconfigurationforwhichthoseresourcesshouldbeused.Asanotherexample,youshouldoftencreatedifferentlayoutsforyouractivities,dependingonthedevice'sscreenorientationandsize.Forexample,whenthedevicescreenisinportraitorientation(tall),youmightwantalayoutwithbuttonstobevertical,butwhenthescreenisinlandscapeorientation(wide),thebuttonsshouldbealignedhorizontally.Tochangethelayoutdependingontheorientation,youcandefinetwodifferentlayoutsandapplytheappropriatequalifiertoeachlayout'sdirectoryname.Then,thesystemautomaticallyappliestheappropriatelayoutdependingonthecurrentdeviceorientation.
    共
    21
    页
    第
    9
    页
     合肥大学毕业论文
    Formoreaboutthedifferentkindsofresourcesyoucanincludeinyourapplicationandhowtocreatealternativeresourcesforvariousdeviceconfigurations,seetheApplicationResourcesdeveloperguide.
    安卓应用基础
    在Java编程语言编写的Android应用程序的Android的SDK工具编译代码以及与任何数据和到一个Android的包,一个归档文件档案资源的.apk后缀,所有的在一个单一的代码.apk文件被认为是一个应用程序,Android的文件,是供电设备来安装应用程序。一旦安装在设备上,每个Android应用程序的生命在它自己的安全沙箱:而Android操作系统是一个多用户Linux系统中,每个应用程序是一个不同的用户。默认情况下,每个应用程序的系统分配一个唯一的Linux用户ID(该ID仅用于由系统是未知的应用程序),系统设置所有的应用程序中的文件权限,以便只有用户ID分配给该应用程序可以访问它们。每个进程都有它自己的虚拟机(VM),因此应用程序的代码在从其他应用程序隔离运行。默认情况下,每个应用程序运行在它自己的Linux进程。Android的启动过程时,应用程序的任何组件需要被执行,然后关闭该进程时,它不再需要或恢复时,系统必须为其他应用程序的内存。这样一来,Android系统实现了最小特权原则,也就是说,每个应用程序,默认情况下,只能访问的组件,它需要做的工作,没有更多,这将创建一个非常安全的环境,使应用程序无法访问的,这就是它没有给予许可制度的部分。但是,有一个应用程序的方法与其他应用程序和应用程序访问系统服务的数据:这有可能为两个应用程序安排共享相同的Linux用户ID,在这种情况下,它们能够相互访问的文件。为了节约使用相同的用户ID系统资源,应用程序
    可以安排运行在相同的Linux进程和共享同一个VM(应用也必须使用相同的证书签名)。应用程序可以请求访问权限,如用户的联系人,短信,可安装存储(SD卡),摄像头,蓝牙等设备的数据,所有应用程序的权限必须由用户在安装时授予。
    共
    21
    页
    第
    10
    页
     合肥大学毕业论文
    这涵盖了基本就如何Android应用程序在系统中存在这个文件的其余部分向您介绍:1、框架的核心组件定义应用程序。2、清单文件中声明组件和应用程序所需的设备功能。3、资源是从应用程序代码分开,并允许您的应用程序正常优化的设备配置各种其行为。
    应用程序组件(ApplicationComponents)
    Android的核心功能之一就是一个应用程序可以使用其它应用程序的元素(如果那个应用程序允许的话)。比如说,如果你的应用程序需要一个图片卷动列表,而另一个应用程序已经开发了一个合用的而又允许别人使用的话,你可以直接调用那个卷动列表来完成工作,而不用自己再开发一个。你的应用程序并没有吸纳或链接其它应用程序的代码,它只是在有需求的时候启动了其它应用程序的那个功能部分。为达到这个目的,系统必须在一个应用程序的一部分被需要时启动这个应用程序,并将那个部分的Java对象实例化。与在其它系统上的应用程序不同,Android应用程序没有为应用准备一个单独的程序入口(比如说,没有main()方法),而是为系统依照需求实例化提供了基本的组件。共有四种组件类型:
    活动(Activities)
    一个activity代表用户界面的一个独立屏幕。例如,一个邮件应用程序应该有一个activity用于显示新邮件列表,另一个activity用于撰写一封邮件,还有一个activity用于读取邮件。尽管所有activitie协同工作以构成邮件应用程序的用户体验,但彼此之间相对独立。应次,不同的应用程序能够从任何一个activity启动(只要邮件应用程序允许)。例如,用户需要分享一张照片,一个拍照应用程序能够启动邮件应用程序的activity。activity是一个实现了Activity的子类,你可以在Activities开发者指导部分了解更多。
    共
    21
    页
    第
    11
    页
     合肥大学毕业论文
    服务(Services)
    service是在后台运行,执行长时间操作或者执行远程操作。service不提供用户界面。例如,当用户在另一个应用程序时,一个service可在后台播放音乐,或者是从网络上获取数据,而不阻断用户与当前activity的交互。其他组件,比如一个activity,为了与该service互动,可以启动或者绑定它。service是一个实现了Service的子类,你可以在Services开发者指导部分了解更多。
    广
    播接收器(Broadcastreceivers)
    广播接收器是一个专注于接收广播通知信息,并做出对应处理的组件。很多广播是源自于系统代码的──比如,通知时区改变、电池电量低、拍摄了一张照片或者用户改变了语言选项。应用程序也可以进行广播──比如说,通知其它应用程序一些数据下载完成并处于可用状态。应用程序可以拥有任意数量的广播接收器以对所有它感兴趣的通知信息予以响应。所有的接收器均继承自BroadcastReceiver基类。广播接收器没有用户界面。然而,它们可以启动一个activity来响应它们收到的信息,或者用NotificationManager来通知用户。通知可以用很多种方式来吸引用户的注意力──闪动背灯、震动、播放声音等等。一般来说是在状态栏上放一个持久的图标,用户可以打开它并获取消息。
    内容提供者(Contentproviders)
    内容提供者将一些特定的应用程序数据供给其它应用程序使用。数据可以存储于文件系统、SQLite数据库或其它方式。内容提供者继承于ContentProvider基类,为其它应用程序取用和存储它管理的数据实现了一套标准方法。然而,应用程序并不直接调用这些方法,而是使用一个ContentResolver对象,调用它的方法作为替代。ContentResolver可以与任意内容提供者进行会话,与其合作来对所有相关交互通讯进行管理。参阅独立的内容提供者ContentProviders章节获得更多关于使用内容提供者的内容。
    共
    21
    页
    第
    12
    页
     合肥大学毕业论文
    每当出现一个需要被特定组件处理的请求时,Android会确保那个组件的应用程序进程处于运行状态,或在必要的时候启动它。并确保那个相应组件的实例的存在,必要时会创建那个实例。Android系统设计的一个独特方面是任何的一个程序都可以启动另一程序的组件。比如,你想让你的程序可以使用照相机拍照,如果已经有了实现这种功能的程序并且你你的程序能使用它(有权限),那么你就没有再要再写一个新的Activity来实现这个功能。你的程序不需要包含或者链接这个拍照程序。相反,你只需要在你的程序中打开这个拍照程序中的实现拍照功能的Activity。当拍完之后,拍好的照片甚至会自动返回给你的程序。者对于用户来说,就好像是想拍照功能的程序就是你的这个程序的一部分一样。当系统启动一个组件之后,如果这个组件所在的程序之前没有运行的话,系统会自动开始这个程序的进程,并初始化这个组件所需要的相关类。比如,你的程序开启了一个拍照功能程序的Activity,这时系统会启动这个Activity所在的程序,所以这个Activity运行在拍照功能的程序当中,而不是在
    你的程序中。所以,不像其他操作系统的中的程序一样,Android程序没有一个单独的入口点(比如没有我们常见的main()函数)。因为系统中的程序运行在自己的独立进程中,并且程序中的文件都有自己的限制其他程序访问的权限,所以,你的程序不能直接激活其他程序中的组件。但是Android系统就可以。具体是这样的实现的,为了激活(activate)其他程序中的组件,你必须向系统发送一个消息来详细说明你要启动其他组件的意图,这样系统才会为你激活这个组件。
    激活组件(ActivatingComponents)
    四大组件中的三个组件——activities、services和broadcastreceiver——是由一种叫intent的异步消息来激活的。这些intents在运行时(runtime)将这些属于你的程序或不同程序的单独的组件绑定在一起(bind),你可以把这些intents看作是需要其他组件的action的messengers。
    共
    21
    页
    第
    13
    页
     合肥大学毕业论文
    一个intent就是一个Intent对象,这个intent定义了一种可以激活(activate)某个特定组件或者某种特定类型的组件,这两种情况分别对应两种intent的定义方式或者显示的或者隐式的。对于activities和services,一个intent定义了要执行的操作(action)(比如,要“view”或者“send”什么)和要操作的数据的URI。比如,一个intent可能会为一个activity传递一个请求来展示一张图片或者打开一个网页。有时,你可以启动一个activity来得到返回的结果,在这个例子中这个activity的返回的结果也是一个Intent(比如,你可以发送一个intent让用户选择一个personalcontact并返回给你——这个返回的intent就包含了一个指向用户选择的联系人的URI)(关于activity和service的启动方式,。下面将介绍。)对于广播接收者来说,intent只是简单的定义了要广播的内容(比如,一个用以表明电池电量很低的广播仅包含了一个表明电池电量很低的字符串)。最后一种组件类型contentprovider并不是由intent来激活的(activate)。而是由接收到ContentResolver的请求时激活的。它们都各自有自己的方法来激活相应的组件:你可以通过传递一个Intent给startActivity()或startActivityForResult()启动一个activity(或者给他一些新的要做的内容)。使用startActivityForResult()你将得到一个返回结果。你可以通过传递一个Intent给startService()来start一个service(或者给一个正在运行的service一些新的指令(instructions))。或者你可以通过把一个Intent传递给bindService()来绑定一个service。你可以通过传递一个Intent给诸如sendBroadcast()、sendOrderedBroadcast()或者sendStickyBroadcast()等方
    法来初始化一个广播。你可以通过调用ContentResolver的query()方法来执行一次contentprovider的查询操作。
    共
    21
    页
    第
    14
    页
     合肥大学毕业论文
    更多的关于intent的内容,可以参看文档中的IntentsandIntentFilters。更多的关于激活特定组件的内容可以参看文档中的:Activities、Services、BroadcastReceiver、ContentProviders。
    关于Manifest文件
    在Android系统可以启动一个应用程序组件之前,Android系统必须通过读取这个程序的AndroidManifest.xml(即manifest文件)文件来确定要启动的组件存在。你的程序必须在这个manifest文件声明用到的所有的组件,并且这个manifest文件必须在项目的根目录下。另外,这个manifest文件还声明一些其他的东西,比如:确定这个程序需要的所有权限,比如Internet访问权限或者读取用户联系人权限。声明这个运行这个程序所需要的最低API版本,这个可以根据开发该程序所使用的API版本。声明该程序所需要的硬件或软件特征(features),比如照相机、蓝牙服务或者多点触屏。声明该程序需要链接(linkagainst)的API库(不是Andorid的frameworkAPIs),比如GoogleMapslibrary。
    组件声明
    Manifest文件的首要任务就是通知系统关于程序中要使用的组件。比如,一个manifest文件可以用如下的方式来声明一个activity:
    [java]viewplaincopy1.2.3.4.5.6.7.8.
...

    共
    21
    页
    第
    15
    页
     合肥大学毕业论文9.
    在元素中,android:icon属性用于指定一个用于标示该程序的icon。在元素中,android:name属性用于确定这个扩展自Activity的子类的全路径名,android:label属性用于标示这个activity的对于用户可见的label。你必须要用以下方式来声明你的程序组件:1、activities:标签2、services:标签3、broadcastreceiver:标签4、contentproviders:标签如果程序中用到activities、services和contentproviders,你没有在manifest文件中声明,那么这些组件将不会被系统知道,结果就是你的程序不能运行。然而,broadcastreceiver既可以在manifest文件中声明也可以在代码中动态创建(BroadcastReceiver),并通过调用registerReceiver()在系统中注册。更多关于怎样为你的程序构建manifest文件,请参看文档TheAndroidManifes.xml文件。
    声明组件的能力
    正如在上面ActivatingComponents中讨论的那样,你可以使用一个Intent来启动activiti
    es、services和broadcastreceiver。你可以通过在intent中注明目标组件的名字(使用的是组件的类名)来显示的启动组件。然而,intents真正强大的地方在与关于intent的actions的概念。通过intent的actions,你可以简单的描述你要执行的操作的类型(并且可以有选择的描述你要处理的数据),可以允许系统在device中找到这个组件并启动它。如果有多个组件可以执行intent中描述的action,这时用户就可以选择一个来执行。系统可以识别能对某intent做出反应的方式是通过将接收到的intent和设备中其他程序的manifest文件的intentfilters进行比较实现的。
    共
    21
    页
    第
    16
    页
     合肥大学毕业论文
    当你在程序的manifest文件中声明一个组件之后,你可以有选择包含intentfilters,这些intentfilters表明了组件对接收自其他程序的intent做出反应的能力(capabilities)。你可以通过添加一个元素作为achildofthecomponent'sdeclarationelement来为你的程序声明一个intentfilter。比如,在一个邮件程序中的一个activity可以编写新的邮件,这样的话你就需要在manifest文件中来声明一个intentfilter来对“发送”intent响应(为了发送邮件)。这样,在你的程序中,一个activity就可以创建一个发送intent(ACTION_SEND),这样当你调用startaActivity()时,系统就会匹配邮件程序中的发送activity并启动它。更多关于创建intentfilters的内容,可以参看IntentsandIntentFilter文档。
    声明运行程序所需的条件
    Andorid系统可以支持很多不同的设备,并且这些设备的性能特征并不相同。为了防止你的程序被安装在不能正常运行你的程序的较低android系统版本上,通过在manifest文件中声明你的程序支持的设备和软件,便变得尤其重要起来。大多数的这些声明仅是一些信息,而系统并不会读取它们,但是其他的服务比如AndroidMarket却会阅读这些声明来帮助通过通过自己的设备搜索软件的用户过滤软件。比如,你的程序需要照相机,并且使用的Android2.1的APIs,那么你就必须在你的manifest文件中声明这些需要。这样的话,AndroidMarket上,在没有照相机或者Android系统版本低于2.1将不能安装你的程序。然而,如果你的程序不需要照相机,你仍可以声明你需要照相机。这种情况下,你的程序必须在运行时做一下检查,来检查这个设备是否含有照相机,如果没有照相机可用,则系统将会使使用照相机的相关程序不能用。下面是一些你在设计和开发你的程序时,必须要考虑的关于设备的一些重要方面:
    屏幕大小和分辨率:
    为了根据屏幕的类型进行分类,Android定义了
    两个特征:屏幕大小和分辨率。屏幕尺寸有:小,中,大,超大;共21页第17页
     合肥大学毕业论文
    屏幕分辨率类型:低分辨率,中分辨率,高分辨率,超高分辨率;默认情况下,你的程序可以兼容所有的屏幕尺寸和分辨率,因为Android系统对你的程序的UI布局和image资源做了适当的调整。
    输入方式:
    很多设备有不同类型的输入方式,比如键盘、轨迹球、五位元导航。如果你的程序需要某特定形式的输入方式,则你必须在manifes文件中使用标签来声明。不过这种情况是比较少的。
    设备配置:
    有许多硬件或软件并不全在Android系统的设备上,比如,一个照相机、光线传感器、某个版本的OpenGL,或者屏幕的保真度(fidelity)。你在任何条件下都不能假定Android设备具备某种特性(feature)(当然得除掉Android标准库的情况),所以如果你的程序使用了某feature,则你必须使用标签来声明。不同地Android平台设备通常运行不同版本的Android,比如Android1.6或者Android2.3。每个后续版本通常包含之前版本所不支持的新增API。InordertoindicatewhichsetofAPIsareavailable,每个平台版本对应一个APILevel(例如,Android1.0对应于APILevel1,Android2.3对应于APILevel9)。如果你使用任何在1.0版之后平台新增的API,你应该使用元素声明最低APILevel是包含这些API的。为你的应用程序声明所有这些要求至关重要,因为,当你在AndroidMarket上发布你的应用程序时,Market使用这些声明来过滤该应用程序是否对于每台设备可用。这样,你的应用程序仅对能够满足你的应用程序要求的设备可用。
    应用程序资源
    一个应用程序不仅仅由代码组成——它需要区别于源代码的资源,比如图片,音频文件,以及任何与应用程序视觉呈现相关联的内容。例如,你应该使用XML文件定义动画,菜单,风格,颜色,以及activity用户界面的布局。使用应用程序资源文件,可以更容易地更新你的应用程序的特性而无需修改代码,并且—通过提供多套可替换
    共
    21
    页
    第
    18
    页
     合肥大学毕业论文
    资源文件—使您能够针对各种设备配置优化你的应用程序(比如不同语言或屏幕大小)。对于你的安卓工程里面包含的每一项资源,SDK构建工具定义一个唯一的正整数ID标识符,你可以使用该标识符从你的应用程序代码中或者从XML文件中定义的其他资源中特指该资源。例如,如果你的应用程序中包含一个名为logo.png图片文件(保存在res/drawable/文件夹里),SDK工具会生成一个资源ID命名为R.drawable.logo,你可以使
    用该ID特指这张图片并插入你的用户界面中。将资源提供工作同你的源代码分隔开来最重要的原因之一是能够使您为不同的设备配置提供可替换的资源文件。例如,在XML中定义UI字符串,你可以将这些字符串翻译成其他语言并保存在特定的文件夹中。然后,基于语言qualifier/修饰词你添加资源文件夹名称(比如res/values-fr/对应于法语字符串)以及用户语言设置,Android系统会给你的UI提供适当的语言字符串。对于你的可替代资源,Android支持许多不同的qualifiers/修饰符。修饰符是包含在你的资源文件夹名称中的一个短字符串,以便界定哪些设备配置可使用这些资源。另一个例子,对于不同的设备屏幕和大小,你应当为你的activities创建不同的布局。例如,当设备屏幕是纵向的(高),你可能希望一个按钮垂直排列的布局,但当屏幕是横向的(宽),按钮应当水平排列。为了根据方向调整布局,你可以定义两个不同的布局文件并给每个布局文件夹提供适当的修饰符。这样,系统会根据特定的设备方向自动为其提供适当的布局。
    参考文献
    [1]作者Android.developer.题目ApplicationFundamentals.网址:developer.android/guide/topics/fundamentals.html,2012年4月20日
    共
    21
    页
    第
    19
    页
    
    

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号