版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
毕业设计论文)外文参考资料及译文译文题目
ApplicationFundamentals--Android学生姓名
学
号:专
业:
计算机科学与技术()所在学院指导教师
信息技术学院职
称:201112月19日1ApplicationFundamentals——AndroidDevelopersAndroidapplicationsarewrittenintheJavaprogramminglanguage.TheAndroidSDKtoolscompilecode—alonganydataandresourcefiles—intoanAndroidpackage,anwithan.apksuffix.Allthecodeinasingle.apkfileisconsideredtobeoneapplicationandisthatOnceonadevice,eachAndroidapplicationinitssecuritysandbox:TheAndroidoperatingsystemisamulti-userLinuxsysteminwhicheachapplicationisadifferentuser.Bydefault,thesystemassignseachapplicationauniqueLinuxuserID(theIDisusedonlybysystemandistheThesystemsetspermissionsforallthefilesinanapplicationsothatonlytheuserIDassignedtothatapplicationcanaccessthem.Eachprocesshasitsownvirtualmachine(VM),soanapplication'scoderunsinisolationfromotherapplications.Bystartstheprocesswhenanyoftheapplication'scomponentsneedtobeexecuted,thenshutsdowntheprocesswhenit'snolongerneededorthesystemmustrecovermemoryforotherapplications.Inthisway,theAndroidsystemimplementstheprincipleofleastprivilege.Thateachapplication,bydefault,hasonlytothecomponentsthatitrequirestodoitsworkandnomore.Thiscreatesaverysecureenvironmentinwhichanapplicationcannotaccesspartsofthesystemforwhichitisnotgivenpermission.owever,therearewaysforanapplicationtosharedatawithotherapplicationsandforanapplicationtoaccesssystemservices:t'spossibletoarrangefortwoapplicationstosharethesameLinuxuserID,inwhichcaseareabletoeachother'sTosystemresources,applicationsthesameuserIDalso2runinthesameandshareVM(theapplicationsmustalsobesignedwiththesamecertificate).Anapplicationcanrequestpermissiontoaccessdevicedatasuchasthe(SDBluetooth,andmore.Allapplicationpermissionsmustbegrantedbytheuseratinstalltime.ThatcoversthebasicsregardinghowanAndroidapplicationexistswithinthesystem.Therestofthisdocumentintroducesyouto:ThecoreframeworkcomponentsthatdefineyourapplicationThemanifestfileinwhichyoudeclarecomponentsandrequireddevicefeaturesforyourapplication.Resourcesthatfromyourapplicationtogracefullyoptimizeitsbehaviorforavarietyofdeviceconfigurations.ApplicationComponentsApplicationcomponentsaretheessentialbuildingblocksofanAndroidapplication.Eachcomponentisadifferentpointthroughwhichtheapplication.Notallcomponentsentrypointsfortheuserandsomedependoneachother,buteachoneexistsasitsentityandplaysaspecificroleeachoneauniquebuildingblockthathelpsdefineyourapplication'soverallbehavior.Therearefourdifferenttypesofapplicationcomponents.Eachtypeservesadistinctpurposeandhasadistinctlifecyclethatdefineshowthecomponentiscreatedanddestroyed.Herearethefourtypesofapplicationcomponents:ActivitiesAnactivityrepresentsasinglescreenwithauserinterface.Forexample,anemailapplicationmighthaveoneactivitythatshowsalistofactivityanemail,activity3forreadingemails.AlthoughtheactivitiesworktogethertoformacohesiveuseroneoftheAsaapplicationstartoftheseactivities(iftheemailapplicationallowsit).Forexample,acameraapplicationthenewmail,inorderfortheusertoshareapicture.AnactivityisimplementedasasubclassofandyoucanlearnmoreaboutitintheActivitiesdeveloperguide.ServicesAserviceisacomponentthatrunsinthebackgroundtoperformlong-runningtoAservicedoesnotprovideauserinterface.Forexample,aservicemightplaymusicintheuserisinaapplication,itmightfetchdataoverthenetworkwithoutblockinguserinteractionwithanactivity.Anothercomponent,suchasanactivity,canstarttheserviceandletitrunorbindtoitinordertointeractwithit.AserviceisimplementedasasubclassofServiceandyoucanlearnmoreaboutitintheServicesdeveloperguide.ContentprovidersAcontentproviderasetofapplicationdata.Youcanstoreinfilesystem,anSQLitedatabase,ontheweb,oranyotherpersistentstoragelocationyourapplicationcanaccess.Throughtheotherapplicationscanquery(ifthecontentproviderallowsit).Forexample,theAndroidsystemprovidesacontentproviderthattheuser'scontactAssuch,anyapplicationwiththeproperpermissionscanquerypartofthecontentprovider(suchasContactsContract.Data)toreadandwriteinformationaboutaparticularperson.Contentprovidersarealsousefulforreadingandwritingdatathat4isprivatetoandForexample,NotePadsampleapplicationusesacontentprovidertosavenotes.contentproviderisimplementedasasubclassofContentProviderandmustastandardofAPIsenableotherapplicationstoperformtransactions.Forinformation,seetheContentdeveloperguide.roadcastreceiversAbroadcastreceiverisacomponentthatrespondstosystem-widebroadcastannouncements.broadcastsfromthe—forexample,abroadcastannouncingthatthescreenhasturnedoff,thebatteryislow,awascaptured.broadcasts—forexample,toletotherapplicationsknowthatsomedatahasbeendownloadedtothedeviceandisavailableforthemtouse.Althoughbroadcastreceiversdon'tdisplayauserinterface,theymaycreateastatusnotificationalerttheuserwhenaeventoccurs.Morecommonly,though,abroadcastreceiverisjusta"gateway"toothercomponentsandisintendedtodoaveryminimalamountofwork.Forinstance,itmightinitiateaservicetoperformsomeworkbasedontheevent.AbroadcastreceiverisimplementedasasubclassofBroadcastReceiverandeachbroadcastisdeliveredasanIntentobject.Formoreinformation,seetheBroadcastReceiverclass.AuniqueaspectofAndroidsystemdesignthatapplicationcanapplication’sifwantusertocaptureaphotowiththecamera,probablyapplicationthatdoesthatandyourapplicationcanuseit,insteadofdevelopinganactivitytocaptureaphotoyourself.Youdon'tneedtoincorporateoreventocameraapplication.Instead,youtheactivityinapplicationthatcaptures5aphoto.Whencomplete,thephotoisevenreturnedtoyourapplicationsoyoucanuseit.Totheuser,itseemsasifthecameraisactuallyapartofyourapplication.Whenthesystemstartsacomponent,itstartstheprocessforthatapplication(ifit'snotalreadyrunning)andinstantiatestheclassesneededforthecomponent.Forexample,ifyourapplicationstartstheactivityinthecameraapplicationthatcapturesaphoto,thatactivityrunsintheprocessthatbelongstothecameraapplication,notinyourapplication'sprocess.Therefore,unlikeapplicationsonmostothersystems,Androidapplicationsdon'thaveasingleentrypoint(there'snomain()function,forexample).Becausethesystemrunseachapplicationinaseparateprocesswithfilepermissionsthatrestrictaccesstootherapplications,yourapplicationactivateacomponentfromanotherapplication.TheAndroidsystem,however,So,toactivateainanotherapplication,totheyourintenttostartaparticularcomponent.Thesystemthenactivatesthecomponentforyou.ActivatingComponentsThreeofthefourcomponenttypesactivities,services,andbroadcastreceivers—activatedbyanasynchronousmessagecalledan.bindcomponentstoeachat(youcanthinkofthemasthemessengersthatrequestanactionfromothercomponents),whetherthecomponentbelongstoyourapplicationoranother.AnintentiscreatedwithanIntentobject,whichdefinesamessagetoactivateeitheraspecificcomponentoraspecifictypeofcomponent—anintentcanbeeitherexplicitorimplicit,respectively.Forandtheto6(forexample,to"view"or"send"something)andmayspecifytheURIofthedatatoacton(amongotherthingsthatthecomponentbeingstartedmightneedtoknow).Forexample,anintentmightconveyarequestforanactivitytoshowanimageortoopenawebpage.Insomecases,youcanstartanactivitytoreceivearesult,inwhichcase,theactivityalsoreturnstheresultinan(forexample,youcanissueintenttolettheuserpickapersonalcontactandhaveitreturnedtoreturnintentincludesaURIpointingtothechosencontact).Forbroadcastreceivers,theintentsimplydefinestheannouncementbeing(fortoislowincludesonlyaknownactionstringthatindicates"batteryislow").TheRather,itiswhentargetedrequestfromThecontentresolverhandlesalldirecttransactionswiththecontentprovidersothatthecomponentthat'sperformingtransactionswiththeprovidertoobject.Thisleavesalayerofabstractionbetweenthecontentproviderandthecomponentrequestinginformation(forsecurity).Thereareseparatemethodsforactivitingeachtypeofcomponent:Youcanstartangiveittodo)anIntenttostartActivity()orstartActivityForResult()(whenyouwanttheactivitytoreturnaresult).You(ortoanongoingbypassinganIntenttostartService().OryoucanbindtotheservicebypassinganIntenttobindService().YoucaninitiateabroadcastbypassinganIntenttomethodslikesendBroadcast(),sendOrderedBroadcast(),orsendStickyBroadcast().Youcanperformaquerytoacontentproviderbycallingquery()on7aContentResolver.FormoreaboutFiltersdocument.Moreaboutactivatingcomponentsisalsoprovidedinthefollowingdocuments:Activities,Services,BroadcastReceiverandContentProviders.TheManifestFileBeforetheAndroidsystemcanstartanapplicationcomponent,thesystemmustknowthatthecomponentexistsbyreadingtheapplication'sAndroidManifest.xmlfile(the"manifest"file).Yourapplicationmustdeclarecomponentsinfile,whichmustatrootapplicationprojectdirectory.Themanifestdoesanumberofthingsinadditiontodeclaringtheapplication'scomponents,suchas:Identifyanyuserpermissionstheapplicationrequires,suchasInternetaccessorread-accesstotheuser'scontacts.DeclaretheminimumAPILevelrequiredbytheapplication,basedonwhichAPIstheapplicationuses.Declarehardwareandsoftwarefeaturesusedorrequiredbytheapplication,suchascreen.APItobetheAndroidframeworkAPIs),suchastheGoogleMapslibrary.DeclaringcomponentcapabilitiesAsdiscussedabove,inActivatingComponents,youcanuseanIntenttostartservices,andbroadcastYousobyexplicitlynamingthetargetcomponent(usingthecomponentclassname)intheintent.However,therealpowerofintentsliesintheconceptofintentactions.Withintentactions,yousimplydescribethetypeofactionyouwanttoperform(andoptionally,thedatauponwhichyou’dliketoperformtheaction)andallowthesystemtofindacomponenton8thedevicethatcanactionandit.Ifaremultiplecomponentsthatperformactionbytheintent,thentheuserselectswhichonetouse.Thewaythesystemidentifiesthecomponentsthatcanrespondtoanintentisbytheintentreceivedtotheintentfiltersinthemanifestfileofotherapplicationsonthedevice.Wheninyouroptionallyincludeintentfiltersthatdeclarethecapabilitiesofthecomponentsoitcanrespondtointentsfromotherapplications.Youcandeclareanby<intent-filter>elementasachildofthecomponent'sdeclarationelement.Forexample,anemailapplicationwithanactivityforcomposinganewemailmightanintentinmanifestentrytorespondto(insendincanthencreateanintentwiththe“send”actionwhichthesystemmatchestotheemailapplication’s“send”activityandlaunchesitwhenyouinvoketheintentwithstartActivity().Formoreaboutcreatingintentfilters,seetheIntentsandIntentFiltersdocument.DeclaringapplicationrequirementsThereareavarietydevicespoweredandnotthemprovidethesamefeaturesandcapabilities.Inordertopreventyourapplicationfromonthatlackfeaturesneededbyyourapplication,it'simportantthatyouclearlydefineaprofileforthetypesofdevicesyourapplicationsupportsbydeclaringdeviceandsoftwarerequirementsinyourmanifestfile.Mostofthesedeclarationsareinformationalonlyandthesystemdoesnotreadthem,butexternalservicessuchasAndroidMarketdoreadtheminordertoprovidefilteringforuserswhentheysearchforapplicationsfromtheirdevice.9Forexample,ifyourapplicationrequiresacameraandusesAPIsintroducedinAndroid2.1(APILevel7),youshoulddeclaretheseasrequirementsinyourmanifestfile.Thatway,devicesthatnothaveacameraandhaveanAndroidversionlower2.1cannotinstallyourapplicationfromAndroidMarket.However,alsobutdoesnotrequireit.thatcase,yourapplicationmustperformacheckatruntimetodetermineifthedevicehasacameraanddisableanyfeaturesthatusethecameraifoneisnotavailable.Heresomethatconsiderasyoudesignanddevelopyourapplication:ScreensizeanddensityInbytwocharacteristicsforeachdevice:screensizephysicaldimensionsofthescreen)density(thephysicalthepixelsonthescreen,ordotsperinch).Tosimplifyallthedifferenttypesofscreenthesystemthemselectgroupsthatmakethemeasiertotarget.Thescreensizesare:small,normal,large,andextralarge.Theare:extrahighdensity.Byyourisdensities,becausetheAndroidsystemmakestheappropriateadjustmentstoyourUIlayoutandimageresources.However,youshouldcreatespecializedlayoutsforcertainscreensizesandprovidespecializedimagesforcertaindensities,usingalternativelayoutresources,bydeclaringinyourmanifestexactlywhichscreensizesyourapplicationsupportswiththe
element.Formoreinformation,seetheSupportingMultipleScreensdocument.10InputconfigurationsManydevicesprovideadifferenttypeofuserinputmechanism,suchasahardwarekeyboard,atrackball,orafive-waypad.Ifyourapplicationaparticularofdeclareitinyourmanifestwiththe
element.However,itisrarethatanapplicationshouldrequireacertaininputconfiguration.DevicefeaturesTheremanythatmayornotonagivenAndroid-powereddevice,suchasacamera,alightsensor,bluetooth,aversionofthefidelityofYoushouldneverassumethatacertainfeatureisavailableonallAndroid-powereddevices(otherthantheavailabilityofthestandardAndroidlibrary),soyoushoulddeclareanyfeaturesusedbyyourapplicationwiththe<uses-feature>element.PlatformVersionDifferentdevicesoftenrundifferentversionsAndroidplatform,suchasAndroid1.6orAndroid2.3.EachsuccessiveversionoftenincludesadditionalAPIsnotavailableinthepreviousversion.InordertoindicatewhichsetofAPIsareavailable,eachplatformversionspecifiesAPILevelAndroidisAPILevel1andAndroid2.3isAPILevel9).IfyouuseanyAPIsthatwereaddedtotheplatformafterversion1.0,youshoulddeclaretheminimumAPIAPIswereintroducedusing
element.It'simportantthatyoudeclareallsuchrequirementsyou’reyourapplication,because,whenyoudistributeyourapplicationonAndroidMarket,Marketusesthesedeclarationstofilterwhichapplicationsareavailableoneachdevice.Assuch,yourapplicationshouldbeavailableonlytodevicesthatmeetallyourapplicationrequirements.11FormoreinformationabouthowAndroidMarketfiltersapplicationsbasedonseethedocument.ApplicationResourcesAnofthancode—resourcesthatareseparatefromthesourcecode,suchasimages,audiofiles,ForlayoutofactivityuserinterfaceswithXMLfiles.Usingapplicationresourcesmakesiteasytoupdatevariouscharacteristicsofyourapplicationcodeandbyprovidingalternativeresources—enablesyoutooptimizeyourapplicationforavarietyofdeviceconfigurations(suchasdifferentlanguagesandscreensizes).ForeveryyouinyourAndroidproject,SDKbuildtoolsdefineauniqueintegerID,whichyoucanusetoreferencetheresourcefromyourapplicationcodeorfromotherresourcesdefinedinXML.Forexample,ifyourapplicationcontainsanimagefilenamedlogo.png(savedintheres/drawable/directory),theSDKtoolsgeneratearesourceIDnamedR.drawable.logo,whichyoucanusetoreferencetheimageandinsertitinyouruserinterface.Oneofmostoffromyoursourcecodeistheabilityfortoalternativefordifferentdeviceconfigurations.example,bydefiningUIstringsinXML,cantranslatethestringsintootherlanguagesandsavestringsinseparatefiles.Then,basedonaqualifieryouappendtostringandthetheappropriatelanguagestringstoyourUI.Androidsupportsmanydifferentqualifiersforyouralternativeresources.Thequalifierisashortstringthatyouincludeinthename12ofyourtoforwhichresourcesbeused.Asanotheryoushouldoftencreatedifferentlayoutsforyouractivities,dependingonthedevice'sForisinportraitorientation(tall),youmightwantalayoutwithbuttonstobevertical,butwhenthescreenisinlandscapeorientation(wide),theontheorientation,youcandefinetwodifferentlayoutsandapplytheappropriatequalifiertoeachlayout'sdirectoryname.Then,thesystemautomaticallyappliestheappropriatelayoutdependingonthecurrentdeviceorientation.Formoreaboutthedifferentkindsofresourcesyoucanincludeinyourapplicationandhowtocreatealternativeresourcesforvariousdeviceconfigurations,seetheApplicationResourcesdeveloperguid
13应用程序基础AndroidDevelopers原文标题:ApplicationFundamentals原文链接/guide/topics/fundamentals.html应用程序组件Android的一个核心特性就是一个应用程序可以使用其它应用程序的元(如果那个应用程序允许的话如如果你的应用程序需要显示一个图片卷列表,而另一个应用程序已经开发了一个合用的而又允许别的应用程序使用的话可以直接调用那个卷列表来完成工作而用自己再开发一个你的应用程序并没有吸纳戒链接其它应用程序的代码是在有需求的时候启动了其它应用程序的那个功能部分。为达到返个目的统必须能够在一个应用程序的任何一部分被需要时启动一个此应用程序的进程并将那个部分的Java对象实例化因此像其它大多数系统上的应用程序,Android应用程序并没有为应用程序提供一个单独的入口点(比如说,没有main()函数而是为系统提供了可以实例化和运行所需的必备组件。一共有四种组件类型:Activityactivity是为用户操作而展示的可视化用户界面例如一个ctivity以展示一个菜单项列表供用户选择戒者显示一些包含说明文字的照片一个短消息应用程序可以包括一个用于显示要发送消息到的联系人列表的ctivity个给选定的联系人写短信的activity以及翻阅以前的短信戒改变设置的其他activity尽管它们一起组成了一个内聚的用户界面但其中每个ctivity都不其它的保持独立。每一个都实现为以Activity为基类的子类。一个应用程序可以另有一个activity戒者如刚才提到的短信应用程序那样,包含很多个。每activity的作用,以及有多少activity,当然是取决于应用程序及其设计的一般情况下总有一个应用程序被标记为用户在应用程序启动的时候第一个看到的一个activity转向另一个靠的是用当前的activity启动下一个。每个activity都被给予一个默认的窗口以行绘制一般情况下返个窗口是14满屏的,但它也可以是一个小的位于其它窗口乀上的浮动窗口。一个ctivity也可以使用附加窗口——例如个在activity运行过程中弹出的供用户响应的对话框,戒是一个当用户选择了屏幕上特定项目后显示的必要信息的窗口。窗口显示的可视内容是由一系列层次化view构成的,返回view均继承自View基类。每个view均控制着窗口中一块特定的矩形区域。父级view包含并组织其子view的布局叶节点v(位于层次结构最底端在它们控制的矩形区域中进行绘制并对用户直达其区域的操作做出响应因此view是activity不用户进行交互的界面例如view可以显示一个小图片并在用户指点它的时候产生动作。Android有一些预置的view供开发者使用——包括按钮、文本域、滚动条、菜单项、复选框等等。view层次结构是由Activity.setContentView()方法放入activity的窗口乀中的。contentview是位于层次结构根位置的iew对象参见独立的用户界面文档以获取关于view层次结构的更多信息Serviceservice没有可视化的用户界面,而是在一段时间内在后台运行。例如,一个service可以在用户做其它事情的时候在后台播放背景音乐、从网绚上获取数据戒者计算一些东西并提供给需要返个运算结果的使用。每个service都继承自Service基类。一个媒体播放器播放播放列表中的曲目是一个出错的例子放器应用程序可能有一个戒多个activity来给用户选择歌曲并进行播放然而音乐播放返个任务本身出应该由任何activity来处理为用户期望即使在他们离开播放器应用程序而开始做别的事情时音乐仍在继续播放为达到返个目的媒体播放器activity可以启动一个运行于后台的service系统将在返个activity出再显示于屏幕后,仍维持音乐播放service的运行。连接(绑定到一个正在运行的ervice(如果service没有运行则启动)是可能的接后以通过那个service暴露出来的接口不ervice进行通讯。对于音乐service来说,返个接口可以允许用户暂停、回退、停止以及重新开始播放。如同activity和其它组件一样运行于应用程序进程的主线程内。所以它出会对其它组件戒用户界面有任何妨碍们一般会派生一个新线程来执行一些时间消耗型任务(比如音乐回放见稍后的进程和线程。15Broadcastreceiverbroadcastreceiver是一个与注于接收广播通知信息并做出相应处理的组件。许多广播是由系统代码产生的——例如,通知时区改变、电池电量低、拍摄了一张照片戒者用户改变了诧言选项应用程序也可以发起广播——例如通知其它应用程序一些数据已经下载到设备上并处于可用状态。一个应用程序可以拥有任意数量的broadcastreceiver以对所有它认为重要的通知信息予以响应。所有的receiver均继承自BroadcastReceiver类。broadcastreceiver没有用户界面然而它们可以启动一个ctivity来响应它们收到的信息戒者也可以使用NotificationManager来通知用户。通知可以用多种方式来吸引用户的注意力──闪动背光灯震动设备播放声音等等通知一般是在状态上放一个持丽的图标,用户可以打开它并获取消息。Contentprovidercontentprovider将一些特定的应用程序数据供给其它应用程序使用数
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 医院护工保密协议书范本(3篇)
- 舞蹈新生班主题课程设计
- 艺术与设计课程设计案例
- 自然探索团队课程设计
- 简易课程设计
- 英语词汇班课程设计
- 正太分布课程设计
- 绿色蝈蝈课程设计
- 财务制度汇编
- 《刑罚的体系与种类》课件
- 解一元二次方程(公式法)(教学设计)-九年级数学上册同步备课系列
- 冬季传染病预防-(课件)-小学主题班会课件
- 2024年秋新沪教牛津版英语三年级上册 Unit 6 第1课时 教学课件
- 江苏扬州中学教育集团2023-2024学年中考三模数学试题含解析
- 2025年统编版高考历史一轮复习:北洋军阀统治时期的政治、经济与文化 讲义
- 电影放映设备日常维护保养规程
- TSHZSAQS 00255-2024 食葵病虫害防治技术规范
- 食材配送消防安全应急预案
- 《供应链管理》期末考试复习题库(含答案)
- 招标文件范本江苏版
- 人教版高中地理选择性必修1第一章地球的运动单元检测含答案
评论
0/150
提交评论