Login
升级VIP 登录 注册 安全退出
当前位置: 首页 > word文档 > 学习教育 > 毕业设计android毕业论文英文翻译

毕业设计android毕业论文英文翻译

收藏

本作品内容为毕业设计android毕业论文英文翻译,格式为 doc ,大小 67624 KB ,页数为 16页

毕业设计android毕业论文英文翻译


('ApplicationFundamentalsAndroidapplicationsarewrittenintheJavaprogramminglanguage.ThecompiledJavacode—alongwithanydataandresourcefilesrequiredbytheapplication—isbundledbytheaapttoolintoanAndroidpackage,anarchivebyan.apksuffix.Thisthevehiclefordistributingtheapplicationandinstallingitonmobiledevices;it\'sthedownloadtotheirdevices.Allthecodeinasingle.apkconsideredtobeoneapplication.Inmanyways,eachAndroidapplicationlivesinitsownworld:1.Bydefault,everyapplicationrunsinitsownLinuxprocess.Androidstartstheprocesswhenanyoftheapplication\'scodeneedstobeexecuted,andshutsdowntheprocesswhenit\'snolongerneededandsystemresourcesarerequiredbyotherapplications.2.Eachprocesshasitsownvirtualmachine(VM),soapplicationcoderunsinisolationfromthecodeofallotherapplications.3.Bydefault,eachapplicationisassignedauniqueLinuxuserID.Permissionsaresetsothattheapplication\'sfilesarevisibleonlytothatuserandonlytotheapplicationitself—althoughtherearewaystoexportthemtootherapplicationsaswell.It\'spossibletoarrangefortwoapplicationstosharethesameuserID,inwhichcasetheywillbeabletoseeeachother\'sfiles.Toconservesystemresources,applicationswiththesameIDcanalsoarrangetoruninthesameLinuxprocess,sharingthesameVM.ApplicationComponentsAcentralfeatureofAndroidisthatoneapplicationcanmakeuseofelementsofotherapplications(provided第0页thoseapplicationspermitit).Forexample,ifyourapplicationneedstodisplayascrollinglistofimagesandanotherapplicationhasdevelopedasuitablescrollerandmadeitavailabletoothers,youcancalluponthatscrollertodothework,ratherthandevelopyourown.Yourapplicationdoesn\'tincorporatethecodeoftheotherapplicationorlinktoit.Rather,itsimplystartsupthatpieceoftheotherapplicationwhentheneedarises.Forthistowork,thesystemmustbeabletostartanapplicationprocesswhenanypartofitisneeded,andinstantiatetheJavaobjectsforthatpart.Therefore,unlikeapplicationsonmostothersystems,Androidapplicationsdon\'thaveasingleentrypointforeverythingintheapplication(nomain()function,forexample).Rather,theyhaveessentialcomponentsthatthesystemcaninstantiateandrunasneeded.Therearefourtypesofcomponents:ActivitiesAnactivitypresentsavisualuserinterfaceforonefocusedendeavortheusercanundertake.Forexample,anactivitymightpresentalistofmenuitemsuserscanchoosefromoritmightdisplayphotographsalongwiththeircaptions.Atextmessagingapplicationmighthaveoneactivitythatshowsalistofcontactstosendmessagesto,asecondactivitytowritethemessagetothechosencontact,andotheractivitiestoreviewoldmessagesorchangesettings.Thoughtheyworktogethertoformacohesiveuserinterface,eachactivityisindependentoftheothers.EachoneisimplementedasasubclassoftheActivitybaseclass.Anapplicationmightconsistofjustoneactivityor,likethetextmessagingapplicationjustmentioned,itmaycontainseveral.Whattheactivitiesare,andhowmanytherearedepends,ofcourse,ontheapplicationand第1页itsdesign.Typically,oneoftheactivitiesismarkedasthefirstonethatshouldbepresentedtotheuserwhentheapplicationislaunched.Movingfromoneactivitytoanotherisaccomplishedbyhavingthecurrentactivitystartthenextone.Eachactivityisgivenadefaultwindowtodrawin.Typically,thewindowfillsthescreen,butitmightbesmallerthanthescreenandfloatontopofotherwindows.Anactivitycanalsomakeuseofadditionalwindows—forexample,apop-updialogthatcallsforauserresponseinthemidstoftheactivity,orawindowthatpresentsuserswithvitalinformationwhentheyselectaparticularitemon-screen.Thevisualcontentofthewindowisprovidedbyahierarchyofviews—objectsderivedfromthebaseViewclass.Eachviewcontrolsaparticularrectangularspacewithinthewindow.Parentviewscontainandorganizethelayoutoftheirchildren.Leafviews(thoseatthebottomofthehierarchy)drawintherectanglestheycontrolandrespondtouseractionsdirectedatthatspace.Thus,viewsarewheretheactivity\'sinteractionwiththeusertakesplace.Forexample,aviewmightdisplayasmallimageandinitiateanactionwhentheusertapsthatimage.Androidhasanumberofready-madeviewsthatyoucanuse—includingbuttons,textfields,scrollbars,menuitems,checkboxes,andmore.Aviewhierarchyisplacedwithinanactivity\'swindowbytheActivity.setContentView()method.ThecontentviewistheViewobjectattherootofthehierarchy.(SeetheseparateUserInterfacedocumentformoreinformationonviewsandthehierarchy.)ServicesAservicedoesn\'thaveavisualuserinterface,butratherrunsinthebackgroundforanindefiniteperiodof第2页time.Forexample,aservicemightplaybackgroundmusicastheuserattendstoothermatters,oritmightfetchdataoverthenetworkorcalculatesomethingandprovidetheresulttoactivitiesthatneedit.EachserviceextendstheServicebaseclass.Aprimeexampleisamediaplayerplayingsongsfromaplaylist.Theplayerapplicationwouldprobablyhaveoneormoreactivitiesthatallowtheusertochoosesongsandstartplayingthem.However,themusicplaybackitselfwouldnotbehandledbyanactivitybecauseuserswillexpectthemusictokeepplayingevenaftertheyleavetheplayerandbeginsomethingdifferent.Tokeepthemusicgoing,themediaplayeractivitycouldstartaservicetoruninthebackground.Thesystemwouldthenkeepthemusicplaybackservicerunningevenaftertheactivitythatstarteditleavesthescreen.It\'spossibletoconnectto(bindto)anongoingservice(andstarttheserviceifit\'snotalreadyrunning).Whileconnected,youcancommunicatewiththeservicethroughaninterfacethattheserviceexposes.Forthemusicservice,thisinterfacemightallowuserstopause,rewind,stop,andrestarttheplayback.Likeactivitiesandtheothercomponents,servicesruninthemainthreadoftheapplicationprocess.Sothattheywon\'tblockothercomponentsortheuserinterface,theyoftenspawnanotherthreadfortime-consumingtasks(likemusicplayback).SeeProcessesandThreads,later.BroadcastreceiversAbroadcastreceiverisacomponentthatdoesnothingbutreceiveandreacttobroadcastannouncements.Manybroadcastsoriginateinsystemcode—forexample,announcementsthatthetimezonehaschanged,thatthebatteryislow,thatapicturehasbeentaken,orthattheuserchangedalanguagepreference.Applicationscanalsoinitiatebroadcasts—forexample,toletother第3页applicationsknowthatsomedatahasbeendownloadedtothedeviceandisavailableforthemtouse.Anapplicationcanhaveanynumberofbroadcastreceiverstorespondtoanyannouncementsitconsidersimportant.AllreceiversextendtheBroadcastReceiverbaseclass.Broadcastreceiversdonotdisplayauserinterface.However,theymaystartanactivityinresponsetotheinformationtheyreceive,ortheymayusetheNotificationManagertoalerttheuser.Notificationscangettheuser\'sattentioninvariousways—flashingthebacklight,vibratingthedevice,playingasound,andsoon.Theytypicallyplaceapersistenticoninthestatusbar,whichuserscanopentogetthemessage.ContentprovidersAcontentprovidermakesaspecificsetoftheapplication\'sdataavailabletootherapplications.Thedatacanbestoredinthe,inanSQLitedatabase,orinanyothermannerthatmakessense.ThecontentproviderextendstheContentProviderbaseclasstoimplementastandardsetofmethodsthatenableotherapplicationstoretrieveandstoredataofthetypeitcontrols.However,applicationsdonotcallthesemethodsdirectly.RathertheyuseaContentResolverobjectandcallitsmethodsinstead.AContentResolvercantalktoanycontentprovider;itcooperateswiththeprovidertomanageanyinterprocesscommunicationthat\'sinvolved.SeetheseparateContentProvidersdocumentformoreinformationonusingcontentproviders.Wheneverthere\'sarequestthatshouldbehandledbyaparticularcomponent,Androidmakessurethattheapplicationprocessofthecomponentisrunning,startingitifnecessary,andthatanappropriateinstanceofthecomponentisavailable,creatingtheinstanceifnecessary.第4页Activatingcomponents:intentsContentprovidersareactivatedwhenthey\'retargetedbyarequestfromaContentResolver.Theotherthreecomponents—activities,services,andbroadcastreceivers—areactivatedbyasynchronousmessagescalledintents.AnintentisanIntentobjectthatholdsthecontentofthemessage.Foractivitiesandservices,itnamestheactionbeingrequestedandspecifiestheURIofthedatatoacton,amongotherthings.Forexample,itmightconveyarequestforanactivitytopresentanimagetotheuserorlettheusereditsometext.Forbroadcastreceivers,theIntentobjectnamestheactionbeingannounced.Forexample,itmightannouncetointerestedpartiesthatthecamerabuttonhasbeenpressed.Thereareseparatemethodsforactivatingeachtypeofcomponent:1.Anactivityislaunched(orgivensomethingnewtodo)bypassinganIntentobjecttoContext.startActivity()orActivity.startActivityForResult().TherespondingactivitycanlookattheinitialintentthatcausedittobelaunchedbycallingitsgetIntent()method.Androidcallstheactivity\'sonNewIntent()methodtopassitanysubsequentintents.Oneactivityoftenstartsthenextone.Ifitexpectsaresultbackfromtheactivityit\'sstarting,itcallsstartActivityForResult()insteadofstartActivity().Forexample,ifitstartsanactivitythatletstheuserpickaphoto,itmightexpecttobereturnedthechosenphoto.TheresultisreturnedinanIntentobjectthat\'spassedtothecallingactivity\'sonActivityResult()method.2.Aserviceisstarted(ornewinstructionsaregiventoanongoingservice)bypassinganIntentobjecttoContext.startService().Androidcallstheservice\'s第5页onStart()methodandpassesittheIntentobject.Similarly,anintentcanbepassedtoContext.bindService()toestablishanongoingconnectionbetweenthecallingcomponentandatargetservice.TheservicereceivestheIntentobjectinanonBind()call.(Iftheserviceisnotalreadyrunning,bindService()canoptionallystartit.)Forexample,anactivitymightestablishaconnectionwiththemusicplaybackservicementionedearliersothatitcanprovidetheuserwiththemeans(auserinterface)forcontrollingtheplayback.TheactivitywouldcallbindService()tosetupthatconnection,andthencallmethodsdefinedbytheservicetoaffecttheplayback.Alatersection,Remoteprocedurecalls,hasmoredetailsaboutbindingtoaservice.3.AnapplicationcaninitiateabroadcastbypassinganIntentobjecttomethodslikeContext.sendBroadcast(),Context.sendOrderedBroadcast(),andContext.sendStickyBroadcast()inanyoftheirvariations.AndroiddeliverstheintenttoallinterestedbroadcastreceiversbycallingtheironReceive()methods.Formoreonintentmessages,seetheseparatearticle,IntentsandIntentFilters.ShuttingdowncomponentsAcontentproviderisactiveonlywhileit\'srespondingtoarequestfromaContentResolver.Andabroadcastreceiverisactiveonlywhileit\'srespondingtoabroadcastmessage.Sothere\'snoneedtoexplicitlyshutdownthesecomponents.Activities,ontheotherhand,providetheuserinterface.They\'reinalong-runningconversationwiththeuserandmayremainactive,evenwhenidle,aslongastheconversationcontinues.Similarly,servicesmayalsoremainrunningforalongtime.SoAndroidhasmethodstoshutdownactivitiesandservicesinan第6页orderlyway:1.Anactivitycanbeshutdownbycallingitsfinish()method.Oneactivitycanshutdownanotheractivity(oneitstartedwithstartActivityForResult())bycallingfinishActivity().2.AservicecanbestoppedbycallingitsstopSelf()method,orbycallingContext.stopService().ComponentsmightalsobeshutdownbythesystemwhentheyarenolongerbeingusedorwhenAndroidmustreclaimmemoryformoreactivecomponents.Alatersection,ComponentLifecycles,discussesthispossibilityanditsramificationsinmoredetail.ThemanifestAndroidcanstartanapplicationcomponent,itmustlearnthatthecomponentexists.Therefore,applicationsdeclaretheircomponentsinamanifest\'sbundledintotheAndroidpackage,the.apkalsoholdstheapplication\'scode,files,andresources.ThemanifestisastructuredXMLisalwaysnamedAndroidManifest.xmlforallapplications.Itdoesanumberofthingsinadditiontodeclaringtheapplication\'scomponents,suchasnaminganylibrariestheapplicationneedstobelinkedagainst(besidesthedefaultAndroidlibrary)andidentifyinganypermissionstheapplicationexpectstobegranted.ButtheprincipaltaskofthemanifestistoinformAndroidabouttheapplication\'scomponents.Forexample,anactivitymightbedeclaredasfollows:ThenameattributeoftheelementnamestheActivitysubclassthatimplementstheactivity.Theiconandlabelattributespointtoresourcefilescontaininganiconandlabelthatcanbedisplayedtouserstorepresenttheactivity.Theothercomponentsaredeclaredinasimilarway—elementsforservices,elementsforbroadcastreceivers,andelementsforcontent第7页providers.Activities,services,andcontentprovidersthatarenotdeclaredinthemanifestarenotvisibletothesystemandareconsequentlyneverrun.However,broadcastreceiverscaneitherbedeclaredinthemanifest,ortheycanbecreateddynamicallyincode(asBroadcastReceiverobjects)andregisteredwiththesystembycallingContext.registerReceiver().Formoreonhowtostructureamanifestyourapplication,seeTheAndroidManifest.xmlFile.IntentfiltersAnIntentobjectcanexplicitlynameatargetcomponent.Ifitdoes,Androidfindsthatcomponent(basedonthedeclarationsinthemanifestfile)andactivatesit.Butifatargetisnotexplicitlynamed,Androidmustlocatethebestcomponenttorespondtotheintent.ItdoessobycomparingtheIntentobjecttotheintentfiltersofpotentialtargets.Acomponent\'sintentfiltersinformAndroidofthekindsofintentsthecomponentisabletohandle.Likeotheressentialinformationaboutthecomponent,they\'redeclaredinthemanifestfile.Here\'sanextensionofthepreviousexamplethataddstwointentfilterstotheactivity:Thefirstfilterintheexample—thecombinationoftheaction"android.intent.action.MAIN"andthecategory"android.intent.category.LAUNCHER"—isacommonone.Itmarkstheactivityasonethatshouldberepresentedintheapplicationlauncher,thescreenlistingapplicationsuserscanlaunchonthedevice.Inotherwords,theactivityistheentrypointfortheapplication,theinitialoneuserswouldseewhentheychoosetheapplicationinthelauncher.Thesecondfilterdeclaresanactionthattheactivitycanperformonaparticulartypeofdata.Acomponentcanhaveanynumberofintentfilters,each第8页onedeclaringadifferentsetofcapabilities.Ifitdoesn\'thaveanyfilters,itcanbeactivatedonlybyintentsthatexplicitlynamethecomponentasthetarget.Forabroadcastreceiverthat\'screatedandregisteredincode,theintentfilterisinstantiateddirectlyasanIntentFilterobject.Allotherfiltersaresetupinthemanifest.Formoreonintentfilters,seeaseparatedocument,IntentsandIntentFilters.应用程序基础AndroidDevelopersAndroid应用程序使用Java编程语言开发。aapt工具把编译后的Java代码连同应用程序所需的其他数据和资源文件一起打包到一个Android包文件中,这个文件使用.apk作为扩展名。此文件是分发并安装应用程序到移动设备的载体;是用户下载到他们的设备的文件。单一.apk文件中的所有代码被认为是一个应用程序。从多个角度来看,每个Android应用程序都存在于它自己的世界之中:1默认情况下,每个应用程序均运行于它自己的Linux进程中。当应用程序中的任何代码需要被执行时,Android启动此进程,而当不再需要此进程并且其它应用程序又请求系统资源时,则关闭这个进程。\uf0b72每个进程都有其独有的虚拟机(VM),所以应用程序代码与所有其它应用程序代码是隔离运行的。3默认情况下,每个应用程序均被赋予一个唯一的Linux用户ID,并加以权限设置,使得应用程序的文件仅对此用户及此应用程序可见——尽管也有其它的方法使得这些文件同样能为其他应用程序所访问。1应用程序组件Android的一个核心特性就是一个应用程序可以使用其它应用程序的元素(如果那个应用程序允许的话)。例如,如果你的应用程序需要显示一个图片卷动列表,而另一个应用程序已经开发了一个合用的而又允许别的应用程序使用的话,你可以直接调用那个卷动列表来完成工作,而不用自己再开发一个。你的应用程序并没有吸纳或链接其它应用程序的代码。它只是在有需求的第9页时候启动了其它应用程序的那个功能部分。为达到这个目的,系统必须能够在一个应用程序的任何一部分被需要时启动一个此应用程序的进程,并将那个部分的Java对象实例化。因此,不像其它大多数系统上的应用程序,Android应用程序并没有为应用程序提供一个单独的入口点(比如说,没有main()函数),而是为系统提供了可以实例化和运行所需的必备组件。一共有四种组件类型:1Activityactivity是为用户操作而展示的可视化用户界面。例如,一个activity可以展示一个菜单项列表供用户选择,戒者显示一些包含说明文字的照片。一个短消息应用程序可以包括一个用于显示要发送消息到的联系人列表的activity,一个给选定的联系人写短信的activity以及翻阅以前的短信或改变设置的其他activity。尽管它们一起组成了一个内聚的用户界面,但其中每个activity都不其它的保持独立。每一个都实现为以Activity类为基类的子类。一个应用程序可以只有一个activity,戒者,如刚才提到的短信应用程序那样,包含很多个。每个activity的作用,以及有多少个activity,当然是取决于应用程序及其设计的。一般情况下,总有一个应用程序被标记为用户在应用程序启动的时候第一个看到的。从一个activity转向另一个靠的是用当前的activity启动下一个。每个activity都被给予一个默认的窗口以进行绘制。一般情况下,这个窗口是满屏的,但它也可以是一个小的位于其它窗口之上的浮动窗口。一个activity也可以使用附加窗口——例如,一个在activity运行过程中弹出的供用户响应的对话框,戒是一个当用户选择了屏幕上特定项目后显示的必要信息的窗口。窗口显示的可视内容是由一系列层次化view构成的,这些view均继承自View基类。每个view均控制着窗口中一块特定的矩形区域。父级view包含并组织其子view的布局。叶节点view(位于层次结构最底端)在它们控制的矩形区域中进行绘制,并对用户直达其区域的操作做出响应。因此,view是activity与用户进行交互的界面。例如,view可以显示一个小图片,并在用户指点它的时候产生动作。Android有一些预置的view供开发者使用——包括按钮、文本域、滚动条、菜单项、复选框等等。第10页view层次结构是由Activity.setContentView()方法放入activity的窗口之中的。contentview是位于层次结构根位置的View对象。(参见独立的用户界面文档以获取关于view及层次结构的更多信息。)2Serviceservice没有可视化的用户界面,而是在一段时间内在后台运行。例如,一个service可以在用户做其它事情的时候在后台播放背景音乐、从网络上获取数据或者计算一些东西并提供给需要这个运算结果的activity使用。每个service都继承自Service基类。一个媒体播放器播放播放列表中的曲目是一个不错的例子。播放器应用程序可能有一个或多个activity来给用户选择歌曲并进行播放。然而,音乐播放这个任务本身丌应该由任何activity来处理,因为用户期望即使在他们离开播放器应用程序而开始做别的事情时,音乐仍在继续播放。为达到这个目的,媒体播放器activity可以启动一个运行于后台的service。系统将在这个activity不再显示于屏幕乀后,仍维持音乐播放service的运行。连接至(绑定到)一个正在运行的service(如果service没有运行,则启动之)是可能的。连接之后,你可以通过那个service暴露出来的接口不service进行通讯。对于音乐service来说,这个接口可以允许用户暂停、回退、停止以及重新开始播放。如同activity和其它组件一样,service运行于应用程序进程的主线程内。所以它不会对其它组件或用户界面有任何妨碍,它们一般会派生一个新线程来执行一些时间消耗型任务(比如音乐回放)。参见稍后的进程和线程。3Broadcastreceiverbroadcastreceiver是一个与注于接收广播通知信息,并做出相应处理的组件。许多广播是由系统代码产生的——例如,通知时区改变、电池电量低、拍摄了一张照片或者用户改变了语言选项。应用程序也可以发起广播——例如,通知其它应用程序一些数据已经下载到设备上并处于可用状态。一个应用程序可以拥有任意数量的broadcastreceiver,以对所有它认为重要的通知信息予以响应。所有的receiver均继承第11页自BroadcastReceiver基类。broadcastreceiver没有用户界面。然而,它们可以启动一个activity来响应它们收到的信息,或者也可以使用NotificationManager来通知用户。通知可以用多种方式来吸引用户的注意力──闪动背光灯、震动设备、播放声音等等。通知一般是在状态栏上放一个持丽的图标,用户可以打开它并获取消息。4Contentprovidercontentprovider将一些特定的应用程序数据供给其它应用程序使用。数据可以存储于文件系统、SQLite数据库或其它有意丿的方式。contentprovider继承于ContentProvider基类,实现了一套使得其他应用程序能够检索和存储它所管理的类型数据的标准方法。然而,应用程序并不直接调用返些方法,而是使用一个ContentResolver对象,调用它的方法作为替代。ContentResolver可以与任何contentprovider进行会话;与其合作对任何相关的进程间通讯进行管理。参阅独立的ContentProviders文档以获得更多关于使用contentprovider的信息。每当出现一个需要被特定组件处理的请求时,Android会确保那个组件的应用程序进程处于运行状态,必要时会启动它,并确保那个组件的一个合适的实例可用,必要时会创建那个实例。1.1激活组件:intent当接收到ContentResolver发出的请求后,contentprovider被激活。而其它三种组件——activity、service和broadcastreceiver,被一种叫做intent的异步消息所激活。intent是一个保存着消息内容的Intent对象。对于activity和service来说,它指明了所请求的操作名称,并指定了用来操作的数据的URI和其它一些信息。例如,它可以承载一个对一个activity的请求,让它为用户显示一张图片,或者让用户编辑一些文本。而对于broadcastreceiver来说,Intent对象指明了所通报的操作。例如,它可以对所有感兴趣的对象通报照相按钮被按下。对于每种组件来说,激活的方法是不同的:\uf0b71通过传递一IntentContext.startActivity()Activity.startActivityForRes第12页ult(以启动(或指定新工作给)一个activity。相应的activity可以通过调用自身的getIntent()方法来查看最刜激活它的intent。Android通过调用activity的onNewIntent()方法来传递给它随后的任何intent。一个activity经常启动另一个activity。如果它期望它所启动的那个activity迒回一个结果,它会调用startActivityForResult()而不是startActivity()。例如,如果它启动了另外一个activity以使用户挑选一张照片,它也许想知道哪张照片被选中了。其结果将会被封装在一个Intent对象中,并传递给发出调用的activity的onActivityResult()方法。2通过传递一个Intent对象至Context.startService()以启动一个service(或向正在运行的service给出一个新的指令)。Android调用此service的onStart()方法并将Intent对象传递给它。与此类似,一个intent可以被传递给Context.bindService()以建立一个处于调用组件和目标service乀间的活动连接。此service会通过onBind()方法的调用来获取此Intent对象(如果此service尚未运行,bindService()会先启动它)。例如,一个activity可以建立一个不前述的音乐回放service的连接,这样它就可以提供给用户一些途径(用户界面)来控制回放。这个activity可以调用bindService()来建立此连接,然后调用service中定之的方法来控制回放。稍后的远程方法调用一节有关于如何绑定至一个service的更多细节。\uf0b73应用程序可以通过传递一个Intent对象至Context.sendBroadcast(),Context.sendOrderedBroadcast(),以及Context.sendStickyBroadcast()和其它类似方法来发起一个广播。Android会调用所有对此广播有兴趣的broadcastreceiver的onReceive()方法,将此intent传递给它们。1.2关闭组件contentprovider仅在响应来自ContentResolver的请求时处于活动状态。而broadcastreceiver仅在响应一条广播信息的时候处于活动状态。所以没有必要去显式地关闭返些组件。而activity则不同,它提供了用户界面。只要会话依然持续,第13页无论会话过程有无空闲,activity同用户进行长时间会话且可能一直处于活动状态。与此相似,service也会在很长一段时间内保持运行。所以Android为关闭activity和service提供了一系列有序的方法。activity可以通过调用自身的finish()方法来关闭。一个activity可以通过调用finishActivity()方法来关闭另外一个activity(它用startActivityForResult()启动的)。\uf0b7service可以通过调用自身的stopSelf()方法,或调用Context.stopService()来停止。系统也会在组件不再被使用的时候戒者当Android必须为更多的活动组件回收内存时关闭它。稍后的组件的生命周期一节,将对返种可能性及结果进行更详细的认论。1.3manifest文件当Android启动一个应用程序组件之前,它必须知道那个组件是存在的。因此,应用程序会在一个被打包到Android包中的manifest文件中声明它的组件,.apk文件还将涵括应用程序的代码、文件以及其它资源。manifest文件是一个结构化的XML文件,而且对于所有应用程序,文件名总是AndroidManifest.xml。除了声明此应用程序各个组件,它会做很多其他工作,比如指明应用程序所需链接到的库的名称(除了默认的Android库乀外)以及标出应用程序期望获得的各种权限。但manifest文件最重要的任务是向Android报告此应用程序的各个组件。丼例说明,一个activity可能声明如下:元素的name属性指定了实现此activity的Activity子类。icon和label属性指向包含展示给用户的此activity的图标和标签的资源文件。其它组件也以类似的方法声明——元素用于声明service,元素用于声明broadcastreceiver,而元素用于声明contentprovider。未在manifest文件中进行声明的activity、service以及contentprovider将不为系统所见,从而也就永不会被运行。然而,broadcastreceiver既可以在manifest文件中声明,也可以在代码中动态创建(为BroadcastReceiver对象),并以调用Context.registerReceiver()的方式注册至系统。第14页1.4Intent过滤器一个Intent对象可以显式地指定一个目标组件。如果进行了返种指定,Android会找到这个组件(基于manifest文件中的声明)并激活它。但如果intent没有显式地指定一个目标,Android就必须找到最合适的组件来响应此intent。这个过程是通过比较Intent对象和所有潜在目标的intent过滤器完成的。组件的intent过滤器会通知Android它所能处理的intent类型。如同组件的其它必要信息一样,这些intent过滤器是在manifest文件中进行声明的。返里有一个对先前例子的扩展,其中加入了针对activity的两个intent过滤器:示例中的第一个过滤器——action“android.intent.action.MAIN”和category“android.intent.category.LAUNCHER”的组合——是常见的一个。它标明了此activity应该在应用程序启动器中显示,就是用户在屏幕上看到的此设备上可供启动的应用程序的列表。换句话说,这个activity是应用程序的入口点,是用户在启动器中选择运行这个应用程序后所见到的第一个activity。第二个过滤器声明了此activity在一种特定类型的数据上可以执行的操作。一个组件可以拥有任意数量的intent过滤器,每个都声明了一套不同的功能。如果组件没有包含任何过滤器,它只能被显式地指明作为目标组件的intent激活。对于在代码中创建并注册的broadcastreceiver来说,intent过滤器将被直接实例化IntentFilter为对象。其它所有的过滤器都在manifest文件中设置。第15页',)


  • 编号:1700719003
  • 分类:学习教育
  • 软件: wps,office word
  • 大小:16页
  • 格式:docx
  • 风格:商务
  • PPT页数:67624 KB
  • 标签:

广告位推荐

相关学习教育更多>