毕业设计论文基于Android平台的图书管理系统手机客户端开发_第1页
毕业设计论文基于Android平台的图书管理系统手机客户端开发_第2页
毕业设计论文基于Android平台的图书管理系统手机客户端开发_第3页
毕业设计论文基于Android平台的图书管理系统手机客户端开发_第4页
毕业设计论文基于Android平台的图书管理系统手机客户端开发_第5页
已阅读5页,还剩70页未读 继续免费阅读

下载本文档

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

文档简介

UNIVERSITYOFTECHNOLOGY 毕业设计 题目基于Android平台的图书管理系统手机客户端开发学生姓名xxx学号专业班级通信工程指导教师xxx学院计算机与通信答辩日期2012年6月基于Android平台的图书管理系统手机客户端开发ThedevelopmentoflibrarymanagementsystemisbasedontheAndroidplatformxxx0825理工大学毕业设计理工大学毕业设计 图5.6管理员管理界面5.5.5管理学生用户界面管理学生用户界面是对所有学生用户进行管理的界面,这个界面的主要功能有查找特定用户和查找所有用户两种方式,通过查找,最终把所有用户都显示在界面上。注册功能对应的程序名为com.briup包下的ManagerUserActivity.java.管理学生用户界面如下:图5.7管理用户界面主要代码如下:Intentintent=this.getIntent();Stringusername=intent.getExtras().getString("username").trim();lv_userinfo=(ListView)findViewById(R.id.lv_userinfo);finalListlist=ClientService.findUserInfo(username,"finduserservlet");5.5.6管理图书界面管理图书界面是管理员的另外一个主要功能,管理员能通过这个界面增加新的书籍和查询特定的书籍信息情况,同时,能对查询到的书籍进行删除等功能。注册功能对应的程序名为com.briup包下的ManagerBookActivity.java。管理图书界面如下:图5.8管理图书界面switch(v.getId()){caseR.id.mb_find:Stringbookname=et_bookname.getText().toString().trim();Stringauthorname=et_authorname.getText().toString().trim();if(bookname!=null&&authorname!=null){Toast.makeText(this,"请稍等。。。",Toast.LENGTH_LONG).show();Intentintent=newIntent(this,AdminBookInfoActivity.class);intent.putExtra("bookname",bookname);intent.putExtra("authorname",authorname);startActivity(intent);}else{Toast.makeText(this,"请填写清楚",Toast.LENGTH_LONG).show();}break;caseR.id.mb_addbook:Intentintent1=newIntent(this,AddBookActivity.class);startActivity(intent1);break;caseR.id.mb_reset:et_bookname.setText("");et_authorname.setText("");break;}5.5.7图书增加界面管理员通过增加书籍界面,增加所要增加的书籍的基本信息,通过添加这些信息,是为了普通学生用户通过作者名和书籍名查询时能更好的了解到书籍的基本信息等基本情况。注册功能对应的程序名为com.briup包下的AddBookActivity.java。图书增加界面如下:图5.9增加图书界面Stringnum=1+"";Stringbookname=et_bookname.getText().toString().trim();Stringauthorname=et_authorname.getText().toString().trim();Stringphname=et_phname.getText().toString().trim();Stringlocation=et_location.getText().toString().trim();Stringcategory=et_category.getText().toString().trim();Stringrenttime=et_renttime.getText().toString().trim();num=et_abnum.getText().toString().trim();Stringstr=ClientService.makeBookString(bookname,authorname,phname,location,category,renttime,num,"savebookservlet");Toast.makeText(this,str,Toast.LENGTH_LONG).show();第6章系统测试6.1用户注册测试用户在手机终端打开客户端应用程序后,有两个按钮选择,如果还没有账号,则点击用户注册按钮跳转到注册界面。注册界面需要你输入你的用户名、密码、身份证号、入学年份、性别和所在学院等信息。如果用户填写的信息不全或者遗漏,则提示填写完整。如果注册成功,则跳转到登录模块进行登录。注册无效类:注册信息不完整,提示填写完整。注册有效类:注册信息完整,并且注册信息符合唯一性,跳转到登录界面。用户注册测试如图6.1所示:图6.1注册测试图6.2用户登录测试用户登录分为学生用户登录和管理员登录,两者的登录方式都是只需要提供用户名和密码就可进行登录操作。学生用户登录成功后,跳转到图书查询界面;管理员登录成功后,跳转到管理员界面,管理员界面分为学生管理和图书管理两部分。登录无效类:登录账号或者密码不符,登录不成功,提示错误。登录有效类:登录账号密码相符,登录成功,并跳转到学生用户或管理员相对应的界面。学生用户登录测试如图6.2所示:图6.2学生用户登录测试图管理员登录测试图如图6.3所示:图6.3管理员登录测试图6.3图书查询测试作为图书馆管理系统的主要功能,用户通过用户名和密码登录后,便可以享受图书查询等功能服务。学生用户想要查询的书籍只要提供书籍名和书籍作者,就能查询到该书籍的基本信息。测试无效类:查询的图书不存在,提示查询图书不存在。测试有效类:查询的图书存在,并列出所查询图书的基本信息。图书查询测试如图6.4所示:图6.4图书查询测试图6.4用户管理测试对于图书管理员而言:他们除了上述所具有的权利外,还需要对普通用户进行管理。在用户管理中,通过用户名搜索出特定学生用户或者查询出所有学生用户,在用户列表出来之后,通过长按用户列表上的某一条信息,可以对该用户进行删除操作。测试无效类:查询特定的学生不存在,提示所查询的学生不存在。测试有效类:查询特定学生存在,并列出学生的基本信息。管理员对学生用户进行管理测试图如图6.5所示:图6.5管理员管理学生用户测试图6.5书籍管理测试书籍管理中,除了书籍查询功能外,还有对书籍进行添加的操作,在对书籍进添加操作时,需写明书籍的一些基本信息,比如:书名、作者名、所属科目、所放位置等信息。在书籍查询功能上,可以通过长按查询出来的书籍列表,来删除、更新所选中的书籍。测试无效类:书籍添加信息不完整,提示填写完整。测试有效类:书籍添加信息完整,添加成功。管理员对书籍管理测试如图6.6所示:图6.6管理员添加图书测试图总结经过13周的努力终于完成了基于Android平台的图书管理系统的设计以及论文,本图书管理系统实现一般传统WEB上的图书管理系统所必备的基本功能,并且提供了友好的用户交互界面,让用户操作起来极为方便和快捷,在这13周里,我收获了很多,也付出了很多,从一个系统设计者的角度来说,我体会到了一个系统的设计其实不是想象的那么简单,对于用户来讲,也许手机软件上的一个看似很小的功能,但在系统开发者看来有时却并不显得简单,有句俗话叫“牵一发而动全身”,在一个系统有时一个小小的改动往往会牵涉到一些复杂的业务逻辑和算法,因此作为一个开发者,必须要有十足的耐心,才能将系统尽可能设计的合理,这款系统,我从整体设计和用户交互的UI层,到完成具体功能的业务逻辑层,直至底层数据库的设计,都花了很多时间去思考,做了很多繁琐的工作,但我认为是值得的,因为我做的大量工作换来了用户操作的简便,也为用户提供了良好的体验。在没有做毕业设计之前,觉得以前学过的知识太零碎,只是单纯的概念和计算之类的,并且没有整体的联系和框架,并且也单纯的认为毕业设计只是对以前的知识点的总结,但是通过这次毕业设计发现自己的看法有点太片面。毕业设计不仅是对前面所学知识的一种检验,也是对自己能力的一种提高。通过这次毕业设计使自己明白了原来的知识是非常欠缺的,要以后的工作和生活中都应该不断地学习,努力提高自己的知识和综合素质。在这次毕业设计中,我遇到了很多问题。单从图书管理系统的服务器端来说用到的知识都有XML、Servlet、JDBC、数据库Oracle、等等„„当初学习时,只是听懂了一部分,没有完全理解,所以做整体框架花费了一部分时间,以至于时间比较紧张。至于开发客户端相对来说比较熟练一点。当然,图书管理系统是一个比较大的项目,光调试就要启动数据库、服务器端Tomcat、客户端,一旦中间有什么问题需要检查的地方很多,确实需要细心,耐心,更重要的是技术。因此这次毕业设计让我看到了我们不能只满足于掌握一种计算机语言,其实多种计算机语言之间是相通的,我们要学会联系,只有技术过关了,才能做出好项目。在这次毕业设计中,同学之间互相帮助,有什么不懂得大家一起商量,发现我们所学的知识实在是有限,不过我们能够充分利用网络的优势去查阅资料。在整个设计过程中懂得了许多东西,也培养了独立思考和设计的能力,树立了对知识应用的信心,相信会对今后的学习工作和生活有非常大的帮助,并且提高了自己的动手实践操作能力,使自己充分体会到了设计过程中成功的喜悦。虽然这个设计做的不怎么好,但是在设计过程中所学到的东西是这次课程设计的最大收获和财富,使我终身受益。对于本系统,虽然完成了图书馆管理系统的基本功能,但我觉得还好很多的不足,首先,交互界面虽然尽量做到简洁、方便,但是由于时间和经验的不足,有许多地方还是不能很好的做到美观和简洁的平衡点。本系统虽然完成了传统WEB图书馆管理系统的基本功能,但我觉得还是有很多功能可以有待发挥,比如,图书馆的电子书下载及电子书在线阅读等模块,以上两个模块都没在本系统实现,但我相信,如果能加上这些没有实现的模块,本系统将更加完善。参考文献杨丰盛.《Android应用开发揭秘》[M].北京:机械工业出版社,2010.1吴亚峰,吴亚光.《Android应用案例开发大全》[M].北京:人民邮电出版社,2012韩超.《Android经典应用程序开发》[M].北京:电子工业出版社,2012吴亚峰,于复兴.《Android应用开发完全自学手册--核心技术、传感器、2D/3D、多媒体与典型案例》[M].北京:人民邮电出版社,2012罗杰(美国),李耀亮.《Android应用开发》[M].北京:人民邮电出版社,2010王家林.《大话企业级Android应用开发实践》[M].北京:电子工业出版社,2011.8李刚.《疯狂Android讲义》[M].北京:电子工业出版社,2011.7佘志龙.《AndroidSDK开发范例大全》[M].北京:人民邮电出版社,2010.6郭宏志.《Android应用开发详解》[M].北京:电子工业出版社,2010.10吴亚峰.《Android核心技术与实例详解》[M].北京:电子工业出版社.2010.10李芝兴.《Java程序设计之网络编程》[M].北京:清华大学出版社,2009.8RajKamal.《EMBEDDEDSYSTEMSARCHITECTUREPROGRAMMINGANDDESIGN 》[M].北京:清华大学出版社,2005殷兆麟主编.《Java语言程序设计》[M].北京:高等教育出版社,2002.12(美)IvorHorton著.《Java2编程指南(JDK1.3版)》[M].北京:电子工业出版社,2001.11张建沛.《数据库原理及应用系统开发》[M].北京:中国水利水电出版社,1999.4金尊和等编著.《Java高级编程》[M].北京:电子工业出版社,1997.8肖刚编著.《JavaWeb服务器应用程序设计》[M].北京:电子工业出版,2001.9王迪化等编著.《JSP/Servlet—基于Java最新网站建设工具》[M].北京:清华大学出版社,2001.6林海编著.《浏览器/服务器应用开发》[M].北京:科学出版社.2000.4庞慧娟等.《利用JSP实现基JDBC-ODBC桥的Web数据库的访问》[J].计算机应用,2003年.07期:112-114严潮红.《基于仿真的CAD/CAE几何数据传递研究》[M].南京:南京航空航天大学硕士学位论文,2004Android官方网站/reference/java/net/Socket.html附录一核心代码packagecom.briup.jdbc;importjava.io.*;importjava.sql.DriverManager;importjava.sql.Connection;importjava.util.Properties;publicclassConnectionFactory{privatestaticStringdriver;privatestaticStringurl;privatestaticStringuser;privatestaticStringpassword;static{try{Propertiesprops=newProperties();InputStreamis=ConnectionFactory.class.getResourceAsStream("perties");props.load(is);driver=props.getProperty("jdbc.driver");url=props.getProperty("jdbc.url");user=props.getProperty("jdbc.user");password=props.getProperty("jdbc.password");}catch(Exceptione){e.printStackTrace();}}publicstaticConnectiongetConnection(){Connectionconn=null;try{Class.forName(driver);conn=DriverManager.getConnection(url,user,password);}catch(Exceptione){e.printStackTrace();}returnconn;}}附录二外文文献(原文)ThebasicofdescriptionofandroidsystemThemainstreamofthenextgenerationofopenoperatingsystemswillnotbeonthebutwillappearinthephonethatwecarryeveryday.Openenvironmentwillleadthesenewapplicationsmaybeintegratedintotheseonlineservicesthatalreadyexist,ofcourse,aswithgrowingdataservicesonmobilephonessupportthesecurityflawsonthephoneisalsoincreasinglyclear.Thenatureofthenext-generationoperatingsystem,whethertoprovideacompleteintegratedsecurityplatform.BytheOpenMobileAlliance(openHandsetAllianceledbyGoogle)developedtheansystemisawidelyoptimisticaboutanopensourcephonesystem,thesystemprovidesabasicoperatingsystem,amiddlewareapplicationlayer,ajavadevelopmenttoolsandasystemApplicationcollector(collectionofsystemapplications).TheandroidtheSDKsince2releaseofthefirstandroidphoneinOctober2008beforethebirth.Googleopenedsincowntime,Taiwan'sHTC,themanufactureroftheT-MobileG1estimateG1shipmentshavethanonemillionattheendof2008.AccordingtoindustryinsidersexpecttheG1mobilephonesalesin2009continue.Manyothermobilephonesuppliersinthenearfutureplanstosystem.Aroundanandroidandahugedevelopercommunityhasbeenestablished,whilealotproductsandapplicationsontheandroid.Android'smainsellingpointisthatitenabltoseamlesslyexpandonlineservicestomobilephones.ThisisthemostobviousexampleisGoogle'stightlyintegratedwithGmail,CalendarandContactsWebapplicationsthroughtUsersonlyneedtoprovideanandroidusernameandpassword,thephoneautomaticallysGoogleservices.Theothervendorsarequicklyadapttheirexistinginstantmessaging,socialnetworkingandgamingservices.Androidandmanycompaniesfindnewwaystointegratetheirexistingbusinesstotheandroid.Traditionaldesktopandserveroperatingsystemhasbeenworkingfortheintegrationofsecurityfeatures.Theseindividualsandbusinessapplicationsonasingleplatformisverygood,howeverabusinessphoneplatformlikeandroidisnotveryuseful.Itgivesthehopeofmanyresearchers.Androidisnotparkedinthebodyforotherplatformapplicationsupport:theimplementationoftheapplicationdependsonatop-levelJAVAmiddleware,themiddlewarerunningontheembeddedLinuxkernel.Therefore,developersshoulddeploytheirapplictheAndroidmustuseacustomuserinterfaceenvironment.Inaddition,theandroidsystemapplicationslimittheapplicationtocalleachotherAPIcollaboration,andtheothertoauthenticatetheuserapplication.Althoughtheseapplcertainsafetyfeatures,someofourexperienceddeveloperstocreateAndroidapplicationswhorevealedthatthedesignofsecurityapplicationsisnotalwaysstraightforward.Androidusesasimplepermissionlabeldistributionmodetorestrictaccesstoresources,butthereasonsforthenecessityandconvenienceofotherapplications,thedesignershaveincreasedtheconfusystem.ThispaperattemptstoexplainthecomplexityoftheAndroidsecurity,andpaysomeofthepossibledevelopmentdefectsandapplicationsecurity.Wetrytodrawsomelessonslearned,andhopethatthesafetyofthefuture.Androidapplicationframeworkfordevelopersisamandatoryframework.Itdoesnotmain()functionfunctionorasingleentrypointfortheimplementationofthecontrary,thedevelopermustinthedesignofapplicationcomponents.WedevelopedapplicationstoheloftheandroidsdkTheAndroidsystemdefinesfourkindsofcomponenttype.Activitycomponentthatdefinestheapplicationuserinterface.Usually,theapplicationdeveloperdefineseachactivityscreen.Activitycanstart,itmaypassandreturnvalues.CanbehandledatatimeonlyakeyboardsystemActivity,allotherActivitywillbesuspendedServicecomponentsperformbackgroundprocessing.Theneedforsomeoperationswheactivity,afterthedisappearanceoftheuserinterface(suchasdownloadingafileoritusuallytakesuchactionspeciallydesignedservices.Developerscanalsouseaspecsystemstartup,theserviceisusuallydefinedaremoteprocedurecall(RPC),andothersystemcomponentscanbeusedtosendtheinterfacecommandandretrievedata,aswellastocallbackfunction.ContentProvidercomponentstorageandsharedatawithrelationaldatabaseinterfaces.EachContentsupplierhasanassociated"rights"todescribeitscontentscontains.OthercomponentswhenusedasahandletoexecuteSQLqueries(egSELECT,INSERT,orDELETEcontent.Contsuppliersaretypicallystoredthevaluesonthedatabaserecords,dataretrievalisaspecialcase,thefileisalsosharedbythecontentproviderinterface.Thecomponentsofthebroadcastreceiverastosendamessagefromthemailboxtotheapplication.Typically,thebroadcastmessage,theapplicationcodeimplicitdestinatiotheradioreceiversubscribetothesedestinationsreceivemessagessenttoit.Theapcanalsobesolvedexplicitlybroadcastreceivers,includingthenamespaceallocationThemainmechanismoftheinteractionofthecomponentsoftheComponentInteractiointent,whichisasimplemessageobject,whichcontainsadestinationaddressanddataTheAndroidAPIdefineshisapproachintointent,andusethatinformationtoinitiatsuchasstartanactivity(startActivity(Anintent))startservices(thestartServiceradio(sendBroadcast(Anintent)).Androidframeworktoinformthecallstothesemethperforminthetargetapplicationcode.Thisprocess,theinternalcomponentsofcommucalledanaction.Simplyput,theIntentobjectdefinedinthe"IntenttoimplementtheofthemostpowerfulfeaturesoftheAndroidisallowedavarietyofintentaddressingThedevelopercansolvethespaceofatargetcomponentusingitsapplications,theycanalsospecifyanimplicitname.Inthelattercase,thesystemdeterminesthebestcomponentsbyconsideringtheinstalledapplicationsanduserchoice.Implicitnameiscalledtheactionstringbecauseofhisspecialtypeoftherequestedaction.Suchasaviewactionstring,inanintentdatafieldpointstoanimagefile,thesysreferringtothepreferredimageviewer.Developerscanalsousetheactionstringalargenumberofradiotosendandreceivatthereceivingend,thedevelopersuseanintentfiltertocustomizethespecialactionstring.AndroidDepartment,includingtheadditionalgoaloftheresolutionrules,butanoptionalstringtypeofdatamanipulationisthemostcommon.AndroidapplicationsarewrittenintheJavaprogramminglanguage.ThecompiledJavacode—alongwithanydataandresourcefilesrequiredbytheapplication—isbundledbytheapttoolintoanAndroidpackage,anarchivefilemarkedbyan.apksuffix.Thisfileisthevehiclefordistributingtheapplicationandinstallingitonmobiledevices;it'sthefileusersddevices.Allthecodeinasingle.apkfileisconsideredtobeoneapplication.Inmanyways,eachAndroidapplicationlivesinitsownworld:Bydefault,everyapplicationrunsinitsownLinuxprocess.Androidstartsthwhenanyoftheapplication'scodeneedstobeexecuted,andshutsdowntheprocesswhlongerneededandsystemresourcesarerequiredbyotherapplications.Eachprocesshasitsownvirtualmachine(VM),soapplicationcoderunsinisolationfromthecodeofallotherapplications.Bydefault,eachapplicationisassignedauniqueLinuxuserID.Permissionsathattheapplication'sfilesarevisibleonlytothatuserandonlytotheapplication—altoughtherearewaystoexportthemtootherapplicationsaswell.It'spossibletoarrangefortwoapplicationstosharethesameuserID,inwhilecasabletoseeeachother'sfiles.Toconservesystemresources,applicationswiththesameIDcanalsoarrangetoruninthesameLinuxprocess,sharingthesameVM.ApplicationComponentsAcentralfeatureofAndroidisthatoneapplicationcanmakeuseofelementsofotherapplication(providedthoseapplicationpermitit).Forexample,ifyourapplicationneedsscrollinglistofimagesandanotherapplicationhasdevelopedasuitablescrollerandmadeitavailabletoothers,youcancalluponthatscrollertodothework,ratherthandevelopyapplicationdoesn'tincorporatethecodeoftheotherapplicationorlinktoit.Rather,upthatpieceoftheotherapplicationwhentheneedarises.Forthistowork,thesystemmustbeabletostartanapplicationprocesswhenanyneeded,andinstantiatheeJavaobjectsforthatpart.Therefore,unlikeapplicationsonmostothersystems,Androidapplicationsdon'thaveasingleentrypointforeverythingintheapplication(nomain()function,forexample).Rather,theyhaveessentialcomponentsthatthesystemcaniandrunasneeded.Therearefourtypesofcomponents:ActivitiesAnactivitypresentsavisualuserinterfaceforonefocusedendeavortheusercanexample,anactivitymightpresentalistofmenuitemsuserscanchoosefromoritmiphotographsalongwiththeircaptions.Atextmessagingapplicationmighthaveoneactivitythatshowsalistofcontactstosendmessagesto,asecondactivitytowritethemessagetcontact,andotheractivitiestoreviewoldmessagesorchangeorchangesettings.Toughtogethertoformacohesiveuserinterface,eachactivityisindependentoftheothers.EachoneisimplementedasasubclassoftheActivitybaseclass.Anapplicationmightconsistofjustoneactivityor,likethetextmessagingapplicationjustmentioned,itmaycontainseveral.Whattheactivitiesare,andhowmanytherearedepends,ofcourse,ontheapplicationanditsdesign.Typically,oneoftheactivitiesismarkedastshouldbepresentedtotheuserwhentheapplicationislaunched.Movingfromoneactivitytoanotherisaccomplishedbyhavingthecurrentactivitystartthenextone.Eachactivityisgivenadefaultwindowtodrawin.Typically,thewindowfillsthesmightbesmallerthanthescreenandfloatontopofotherwindows.Anactivitycanalsofadditionalwindows—forexample,apop-updialogthatcallsforauserresponseinthetheactivity,orawindowthatpresentsuserswithvitalinformationwhentheyselectapon-screen.Thevisualcontentofthewindowisprovidedbyahierarchyofviews—objectsderivedfromthebaseViewclass.Eachviewcontrolsaparticularrectangularspacewithinthewindow.Parentviewscontainandorganizethelayoutoftheirchildren.Leafviews(thoseatthebottomofthehierarchy)drawintherectanglestheycontrolandrespondtouseractionsdirectedatthatspace.Thus,viewsarewheretheactivity'sinteractionwiththeusertakesplace.Forexample,aviewmightdisplayasmallimageandinitiateanactionwhentheuserimage.Androidhasanumberofready-madeviewsthatyoucanuse—includingbuttons,textfields,scrollbars,menuitems,checkboxes,andmore.Aviewhierarchyisplacedwithinanactivity'swindowbytheActivity.setContentView()method.ThecontentviewistheViewobjectattherootofthehierarchy.(SeetheseparateUserInterfacedocumentformoreinformationonviewsandthehierarchy.)ServicesAservicedoesn'thaveavisualuserinterface,butratherrunsinthebackgroundforperiodoftime.Forexample,aservicemightplaybackgroundmusicastheuserattendstoothermatters,oritmightfetchdataoverthenetworkorcalculatesomethingandprovidetheresulttoactivitiesthatneedit.EachserviceextendstheServicebaseclass.Aprimeexampleisamediaplayersongsfromaplaylist.Theplayerapplicationwouldprobablyhaveoneormoreactivitiesthatallowtheusertochoosesongsandstartplayingthem.However,themusicplaybackitselfwouldbotbehandledbyanactivitybecauseuserswillexpectthemusictokeepthemusicgoing,themediaplayeractivitycouldstartaservthebackground.Thesystemwouldthenkeepthemusicplaybackservicerunningevenaftertheactivitythatstarteditleavesthescreen.It'spossibletoconnectto(bindto)anongoingservice(andstarttheserviceifirunning).Whileconnected,youcancommunicatewiththeservicethroughaninterfacethattheserviceexposes.Forthemusicservice,thinterfacesmightallowuserstopause,rewind,stop,andrestarttheplayback.Likeactivitiesandtheothercomponents,servicesruninthemainthreadoftheapplicationprocess.Sothattheywon'tblockothercomponentsortheuserinterface,theyoftenspathreadfortime-consumingtasks(likemusicplayback).SeeProcessesandThread,later.BroadcastreceiversAbroadcastreceiverisacomponentthatdoesnothingbutreceiveandreacttobroadcastannouncements.Manybroadcastsoriginateinsystemcode—forexample,announcementsthatthetimezonehaschanged,thatthebatteryislow,thatapicturehasbeentaken,orthattheulanguagepreference.Applicationscanalsoinitiatebroadcasts—forexample,toletotherapplicationsknowthatsomedatahasbeendownloadedtothedeviceandisavailablefouse.Anapplicationcanhaveanynumberofbroadcastreceiverstorespondtorespondtoranyannouncementsitconsidersimportant.AllreceiversextendtheBroadcastReceiverbaseBroadcastreceiversdonotdisplayauserinterface.However,theymaystartanactivityinresponsetotheinformationtheyreceive,ortheymayusetheNotificationManagertoalerttheuser.Notificationscangettheuser'sattentioninvariousways—flashingthebacklight,vibratingthedevice,playingasound,andsoon,Theytypicallyplaceapersistenticoninthestauserscanopentogetthemessage.ContentprovidersAcontentprovidermakesaspecificsetoftheapplication'sdataavailabletootherapplications.Thedatacanbestoredinthefilesystem,inanSQLitedatabase,orinanythatmakessense.ThecontentproviderextendstheContentProviderbaseclasstoimplementastandardsetofmethodsthatenableotherapplicationstoretrieveandstoredataofthetypeitcontrols.However,applicationsdonotcallthesemethodsdirectly.RathertheyuseaConteobjectandcallitsmethodsinstead.AContentResolvercantalktoanycontentprovider;iwiththeprovidertomanageanyinterprocesscommunicationthat'sinvolved.SeetheseparateContentProvidersdocumentformoreinformationonusingcontentproWheneverthere'sarequestthatshouldbehandledbyaparticularcomponent,Androisurethattheapplicationprocessofthecomponentisrunning,startingitifnecessary,andthatanappropriateinstanceofthecomponentisavailable,creatingtheinstanceifnecessary.Activatingcomponents:intentsContentprovidersareactivatedwhenthey'retargetedbyarequestfromaContentResotherthreecomponents—activities,services,andbroadcastreceivers—areactivatedbyasynchronousmessagescalledintents.AnintentisanIntentobjectthatholdsthecontentofthemessage.Foractivitiesandservices,itnamestheactionbeingrequestedandspecifiesthdatatoacton,amongotherthings.Forexample,itmightconveyarequestforanactivitanimagettheuserorlettheusereditsometext.Forbroadcastreceivers,theIntentoactionbeingannounced.Forexample,itmightannouncetointerestedpartiesthatthecamhasbeenpressed.Thereareseparatemethodsforactivatingeachtypeofcomponent:1.Anactivityislaunched(orgivensomethingnewtodo)bypassinganIntentobjecttoContext.startActivity()orActivity.startActivityForResult().TherespondingactivitycainitialintentthatcausedittobelaunchedbycallingitsgetIntent()method.Androidcallstheactivity'sonNewIntent()methodtopassitanysubsequentintents.Oneactivityoftenstone.Ifitexpectsaresultbackfromtheactivityit'sstarting,itcallsstartActivityofstartActivity().Forexample,ifitstartsanactivitythatletstheuserpickaphoto,bereturnedthechosenphoto.TheresultisreturnedinanIntentobjectthat'spassedactivity'sonActivityResult()method.2.Aserviceisstarted(ornewinstructionsaregiventoanongoingservice)bypassiobjecttoContext.startService().Androidcallstheservice'sonStart()methodandpasseobject.Similarly,anintentcanbepassedtoContext.bindService()toestablishanongoingconnectionbetweenthecallingcomponentandatargetservice.TheservicereceivestheIntentobjectinanonBind()call.(Iftheserviceisnotalreadyrunning,bindService()canopit.)Forexample,anactivitymightestablishaconnectionwiththemusicplaybackserviceearliersothatitcanprovidetheuserwiththemeans(auserinterface)forcontrollingtheplayback.TheactivitywouldcallbindService()tosetupthatconnection,andthencallmethodsdefinedbytheservicetoaffecttheplayback.Alatersection,Remoteprocedurecalls,hasmoredetailsaboutbindingtoaservice.3.AnapplicationcaninitiateabroadcastbypassinganIntentobjecttomethodslikeContext.sendStickyBroadcast()inanyoftheirvariations.AndroiddeliverstheintenttobroadcastreceiversbycallingtheironReceive()methods.Formoreonintentmessages,seetheseparatearticle,IntentsandIntentFilters.ShuttingdowncomponentsAcontentproviderisactiveonlywhileit'srespondingtoarequestfromaContentResolver.Andabroadcastreceiverisactiveonlywhileit'srespondingtoabroadcastmessage.Sothere'snoneedtoexplicitlyshutdownthesecomponents.Activities,ontheotherhand,providetheuserinterface.They'reinalong-runningconversationwiththeuserandmayremainactive,evenwhenidle,aslongtime.SoAndroidhasmethodstoshutdownactivitiesandservicesinanorderlyway:1.Anactivitycanbeshutdownbycallingitsfinish()method.Onteactivitycanshutdownanotheractivity(oneitstartedwithstartActivityForResult())bycallingfinishActivity2.AservicecanbestoppedbycallingitsstopSelf()method,orbycallingContext.stComponentsmightalsobeshutdownbythesystemwhentheyarenolongerbeingusewhenAndroidmustreclaimmemoryformoreactivecomponents.Alatersection,ComponentLifecycles,discussesthispossibilityanditsramificationsinmoredetail.ThemanifestfileBeforeAndroidcanstartanapplicationcomponent,itmustlearnthatthecomponentexists.Therefore,applicationsdeclaretheircomponentsinamanifestfilethat'sbundledintotheAndroidpackage,the.apkfilethatalsoholdstheapplication'scode,files,andresourceThemanifestisastructuredXMLfileandisalwaysnamedAndroidManifest.xmlforallapplications.Itdoesanumberofthingsinadditiontodeclaringtheapplication'scomasnaminganylibrariestheapplicationneedstobelinkedagainst(besidesthedefaultAndroidlibrary)andidentifyinganypermissionstheapplicationexpectstobegranted.ButtheprincipaltaskofthemanifestistoinformAndroidabouttheapplication'scomponents.Forexample,anactivitymightbedeclaredasfollows:Thenameattributeofthe<activity>elementnamestheActivitysubclassthatimplemactivity.Theiconandlabelattributespointtoresourcefilescontaininganiconandlabelthatcanbedisplayedtouserstoresourcefilescontaininganiconandlabelthatcanbedisplarepresenttheactivity.Theothercomponentsaredeclaredinasimilarway—<service>elementsforservices,<receiver>elementsforbroadcastreceivers,and<provider>elementsforcontentproviders.Activities,services,andcontentprovidersthatarenotdeclaredinthemanifestarenotvisibletothesystemandareconsequentlyneverrun.However,broadcastreceiverscaneitherbedeclaredinthemanifest,ortheycanbecreateddynamicallyicode(asBroadcastReceiverobjects)andregisteredwiththesystembycallingContext.registerReceiber().Formoreonhowtostructureamanifestfileforyourapplication,seeTheAndroidManifest.xmlFile.IntentfiltersAnIntentobjectcanexplicitl

温馨提示

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

评论

0/150

提交评论