




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
畢 業(yè) 設(shè) 計(論文)外 文 文 獻(xiàn) 翻 譯文獻(xiàn)、資料中文題目:安卓應(yīng)用基礎(chǔ)文獻(xiàn)、資料英文題目:AndroidicationFundantals文獻(xiàn)、資料來源:文獻(xiàn)、資料發(fā)表(出版)日期:院專 業(yè): 計算機(jī)班 級:姓 名:學(xué) 號:指導(dǎo)教師:翻譯日期: 2017.02.14畢業(yè)論文外文及翻譯原 文學(xué)院專學(xué) 生題業(yè)班姓目級名 Android Application Fundamentals 信息與控制工程學(xué)院 計算機(jī)08-1 XXX 性別 X 指 導(dǎo)教師 XXX 職稱 XX 年 月 日外文及翻譯英語原文AndroidApplicationFundamentalsAndroidapplicationsarewrittenintheJavaprogramminglanguage.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:Thecoreframeworkcomponentsthatdefineyourapplication.Themanifestfileinwhichyoudeclarecomponentsandrequireddevicefeaturesforyourapplication.Resourcesthatareseparatefromtheapplicationcodeandallowyourapplicationtogracefullyoptimizeitsbehaviorforavarietyofdeviceconfigurations.ApplicationComponentsApplicationcomponentsaretheessentialbuildingblocksofanAndroidapplication.Eachcomponentisadifferentpointthroughwhichthesystemcanenteryourapplication.Notallcomponentsareactualentrypointsfortheuserandsomedependoneachother,buteachoneexistsasitsownentityandplaysaspecificrole—eachoneisauniquebuildingblockthathelpsdefineyourapplication'soverallbehavior.Therearefourdifferenttypesofapplicationcomponents.Eachtypeservesadistinctpurposeandhasadistinctlifecyclethatdefineshowthecomponentiscreatedanddestroyed.Herearethefourtypesofapplicationcomponents:ActivitiesAnactivityrepresentsasinglescreenwithauserinterface.Forexample,anemailapplicationmighthaveoneactivitythatshowsalistofnewemails,anotheractivitytocomposeanemail,andanotheractivityforreadingemails.Althoughtheactivitiesworktogethertoformacohesiveuserexperienceintheemailapplication,eachoneisindependentoftheothers.Assuch,adifferentapplicationcanstartanyoneoftheseactivities(iftheemailapplicationallowsit).Forexample,acameraapplicationcanstarttheactivityintheemailapplicationthatcomposesnewmail,inorderfortheusertoshareapicture.AnactivityisimplementedasasubclassofActivityandyoucanlearnmoreaboutitintheActivitiesdeveloperguide.ServicesAserviceisacomponentthatrunsinthebackgroundtoperformlong-runningoperationsortoperformworkforremoteprocesses.Aservicedoesnotprovideauserinterface.Forexample,aservicemightplaymusicinthebackgroundwhiletheuserisinadifferentapplication,oritmightfetchdataoverthenetworkwithoutblockinguserinteractionwithanactivity.Anothercomponent,suchasanactivity,canstarttheserviceandletitrunorbindtoitinordertointeractwithit.AserviceisimplementedasasubclassofServiceandyoucanlearnmoreaboutitintheServicesdeveloperguide.ContentprovidersAcontentprovidermanagesasharedsetofapplicationdata.Youcanstorethedatainthefilesystem,anSQLitedatabase,ontheweb,oranyotherpersistentstoragelocationyourapplicationcanaccess.Throughthecontentprovider,otherapplicationscanqueryorevenmodifythedata(ifthecontentproviderallowsit).Forexample,theAndroidsystemprovidesacontentproviderthatmanagestheuser'scontactinformation.Assuch,anyapplicationwiththeproperpermissionscanquerypartofthecontentprovider(suchasContactsContract.Data)toreadandwriteinformationaboutaparticularperson.Contentprovidersarealsousefulforreadingandwritingdatathatisprivatetoyourapplicationandnotshared.Forexample,theNotePadsampleapplicationusesacontentprovidertosavenotes.AcontentproviderisimplementedasasubclassofContentProviderandmustimplementastandardsetofAPIsthatenableotherapplicationstoperformtransactions.Formoreinformation,seetheContentProvidersdeveloperguide.BroadcastreceiversAbroadcastreceiverisacomponentthatrespondstosystem-widebroadcastannouncements.Manybroadcastsoriginatefromthesystem—forexample,abroadcastannouncingthatthescreenhasturnedoff,thebatteryislow,orapicturewascaptured.Applicationscanalsoinitiatebroadcasts—forexample,toletotherapplicationsknowthatsomedatahasbeendownloadedtothedeviceandisavailableforthemtouse.Althoughbroadcastreceiversdon'tdisplayauserinterface,theymaycreateastatusbarnotificationtoalerttheuserwhenabroadcasteventoccurs.Morecommonly,though,abroadcastreceiverisjusta"gateway"toothercomponentsandisintendedtodoaveryminimalamountofwork.Forinstance,itmightinitiateaservicetoperformsomeworkbasedontheevent.AbroadcastreceiverisimplementedasasubclassofBroadcastReceiverandeachbroadcastisdeliveredasanIntentobject.Formoreinformation,seetheBroadcastReceiverclass.AuniqueaspectoftheAndroidsystemdesignisthatanyapplicationcanstartanothercomponent.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.ActivatingComponentsThreeofthefourcomponenttypes—activities,services,andbroadcastreceivers—areactivatedbyanasynchronousmessagecalledanintent.Intentsbindindividualcomponentstoeachotheratruntime(youcanthinkofthemasthemessengersthatrequestanactionfromothercomponents),whetherthecomponentbelongstoyourapplicationoranother.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().youcanbindtotheservicebypassinganIntenttobindService().YoucaninitiateabroadcastbypassinganIntenttomethodslikesendBroadcast(),sendOrderedBroadcast(),orsendStickyBroadcast().Youcanperformaquerytoacontentproviderbycallingquery()onaContentResolver.Formoreinformationaboutusingintents,seetheIntentsandIntentFiltersdocument.Moreinformationaboutactivatingspecificcomponentsisalsoprovidedinthefollowingdocuments:Activities,Services,BroadcastReceiverandContentProviders.DeclaringcomponentsTheprimarytaskofthemanifestistoinformthesystemabouttheapplication'scomponents.Forexample,amanifestfilecandeclareanactivityasfollows:<?<?xmlversion="1.0"encoding="utf-8"?><manifest...><applicationandroid:icon="@drawablepp_icon.png"...><activityandroid:name="ject.ExampleActivity"android:label="@stringxample_label"...>ctivity>...pplication>anifest>Inthe<application>element,theandroid:iconattributepointstoresourcesforaniconthatidentifiestheapplication.Inthe<activity>element,theandroid:nameattributespecifiesthefullyqualifiedclassnameoftheActivitysubclassandtheandroid:labelattributesspecifiesastringtouseastheuser-visiblelabelfortheactivity.Youmustdeclareallapplicationcomponentsthisway:<activity>elementsforactivities<service>elementsforservices<receiver>elementsforbroadcastreceivers<provider>elementsforcontentprovidersActivities,services,andcontentprovidersthatyouincludeinyoursourcebutdonotdeclareinthemanifestarenotvisibletothesystemand,consequently,canneverrun.However,broadcastreceiverscanbeeitherdeclaredinthemanifestorcreateddynamicallyincode(asBroadcastReceiverobjects)andregisteredwiththesystembycallingregisterReceiver().DeclaringcomponentcapabilitiesAsdiscussedabove,inActivatingComponents,youcanuseanIntenttostartactivities,services,andbroadcastreceivers.Youcandosobyexplicitlynamingthetargetcomponent(usingthecomponentclassname)intheintent.However,therealpowerofintentsliesintheconceptofintentactions.Withintentactions,yousimplydescribethetypeofactionyouwanttoperform(andoptionally,thedatauponwhichlikeperformtheaction)andallowthesystemtofindacomponentonthedevicethatcanperformtheactionandstartit.Iftherearemultiplecomponentsthatcanperformtheactiondescribedbytheintent,thentheuserselectswhichonetouse.Thewaythesystemidentifiesthecomponentsthatcanrespondtoanintentisbycomparingtheintentreceivedtotheintentfiltersprovidedinthemanifestfileofotherapplicationsonthedevice.Whenyoudeclareacomponentinyourapplication'smanifest,youcanoptionallyincludeintentfiltersthatdeclarethecapabilitiesofthecomponentsoitcanrespondtointentsfromotherapplications.Youcandeclareanintentfilterforyourcomponentbyaddingan<intent-filter>elementasachildofthecomponent'sdeclarationelement.Forexample,anemailapplicationwithanactivityforcomposinganewemailmightdeclareanintentfilterinitsmanifestentrytorespondto"send"intents(inordertosendemail).Anactivityinyourapplicationcanthencreateanintentwiththe(ACTION_SEND),whichthesystemmatchestotheemailandlaunchesitwhenyouinvoketheintentwithstartActivity().Formoreaboutcreatingintentfilters,seetheIntentsandIntentFiltersdocument.DeclaringapplicationrequirementsThereareavarietyofdevicespoweredbyAndroidandnotallofthemprovidethesamefeaturesandcapabilities.Inordertopreventyourapplicationfrombeinginstalledondevicesthatlackfeaturesneededbyyourapplication,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).simplifyallthedifferenttypesofscreenconfigurations,theAndroidsystemgeneralizesthemintoselectgroupsthatmakethemeasiertotarget.Thescreensizesare:small,normal,large,andextralarge.Thescreendensitiesare:lowdensity,mediumdensity,highdensity,andextrahighdensity.Bydefault,yourapplicationiscompatiblewithallscreensizesanddensities,becausetheAndroidsystemmakestheappropriateadjustmentstoyourUIlayoutandimageresources.However,youshouldcreatespecializedlayoutsforcertainscreensizesandprovidespecializedimagesforcertaindensities,usingalternativelayoutresources,andbydeclaringinyourmanifestexactlywhichscreensizesyourapplicationsupportswiththe<supports-screens>element.Formoreinformation,seetheSupportingMultipleScreensdocument.InputconfigurationsManydevicesprovideadifferenttypeofuserinputmechanism,suchasahardwarekeyboard,atrackball,orafive-waynavigationpad.Ifyourapplicationrequiresaparticularkindofinputhardware,thenyoushoulddeclareitinyourmanifestwiththe<uses-configuration>element.However,itisrarethatanapplicationshouldrequireacertaininputconfiguration.DevicefeaturesTherearemanyhardwareandsoftwarefeaturesthatmayormaynotexistonagivenAndroid-powereddevice,suchasacamera,alightsensor,bluetooth,acertainversionofOpenGL,orthefidelityofthetouchscreen.YoushouldneverassumethatacertainfeatureisavailableonallAndroid-powereddevices(otherthantheavailabilityofthestandardAndroidlibrary),soyoushoulddeclareanyfeaturesusedbyyourapplicationwiththe<uses-feature>element.PlatformVersionDifferentAndroid-powereddevicesoftenrundifferentversionsoftheAndroidplatform,suchasAndroid1.6orAndroid2.3.EachsuccessiveversionoftenincludesadditionalAPIsnotavailableinthepreviousversion.InordertoindicatewhichsetofAPIsareavailable,eachplatformversionspecifiesanAPILevel(forexample,Android1.0isAPILevel1andAndroid2.3isAPILevel9).IfyouuseanyAPIsthatwereaddedtotheplatformafterversion1.0,youshoulddeclaretheminimumAPILevelinwhichthoseAPIswereintroducedusingthe<uses-sdk>element.It'simportantthatyoudeclareallsuchrequirementsforyourapplication,because,whenyoudistributeyourapplicationonGooglePlay,thestoreusesthesedeclarationstofilterwhichapplicationsareavailableoneachdevice.Assuch,yourapplicationshouldbeavailableonlytodevicesthatmeetallyourapplicationrequirements.FormoreinformationabouthowGooglePlayfiltersapplicationsbasedonthese(andother)requirements,seetheFiltersonGooglePlaydocument.ApplicationResourcesAnAndroidapplicationiscomposedofmorethanjustcode—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,theAndroidsystemappliestheappropriatelanguagestringstoyourUI.Androidsupportsmanydifferentqualifiersforyouralternativeresources.Thequalifierisashortstringthatyouincludeinthenameofyourresourcedirectoriesinordertodefinethedeviceconfigurationforwhichthoseresourcesshouldbeused.Asanotherexample,youshouldoftencreatedifferentlayoutsforyouractivities,dependingonthedevice'sscreenorientationandsize.Forexample,whenthedevicescreenisinportraitorientation(tall),youmightwantalayoutwithbuttonstobevertical,butwhenthescreenisinlandscapeorientation(wide),thebuttonsshouldbealignedhorizontally.Tochangethelayoutdependingontheorientation,youcandefinetwodifferentlayoutsandapplytheappropriatequalifiertoeachlayout'sdirectoryname.Then,thesystemautomaticallyappliestheappropriatelayoutdependingonthecurrentdeviceorientation.Formoreaboutthedifferentkindsofresourcesyoucanincludeinyourapplicationandhowtocreatealternativeresourcesforvariousdeviceconfigurations,seetheApplicationResourcesdeveloperguide.中文譯文安卓應(yīng)用基礎(chǔ)1.緒論在Java編程語言編寫的oid應(yīng)用程序的oid的SDK工具編譯代碼以及與任何數(shù)據(jù)和到一個oid的包,一個歸檔文件檔案資源的.apk后綴,所有的在一個單一的代碼.apk文件被認(rèn)為是一個應(yīng)用程序,是oid的文件,供電設(shè)備來安裝應(yīng)用程序。一旦安裝在設(shè)備上,每個oid應(yīng)用程序的生命在它自己的安全沙箱:而oid操作系統(tǒng)是一個多用戶nux系統(tǒng)中,每個應(yīng)用程序是一個不同的用戶。默認(rèn)情況下,每個應(yīng)用程序的系統(tǒng)分配一個唯一的nux用戶IID僅用于由系統(tǒng)是未知的應(yīng)用程序),系統(tǒng)設(shè)置所有的應(yīng)用程序中的文件權(quán)限,以便只有用戶ID分配給該應(yīng)用程序可以訪問它們。每個進(jìn)程都有它自己的虛擬機(jī)(VM),因此應(yīng)用程序的代碼在從其他應(yīng)用程序隔離運(yùn)行。默認(rèn)情況下,每個應(yīng)用程序運(yùn)行在它自己的nuxoid的啟動過程時,應(yīng)用程序的任何組件需要被執(zhí)行,然后關(guān)閉該進(jìn)程時,它不再需要或恢復(fù)時,系統(tǒng)必須為其他應(yīng)用程序的內(nèi)存。這樣一來,Android系統(tǒng)實現(xiàn)了最小特權(quán)原則,也就是說,每個應(yīng)用程序,默認(rèn)情況下,只能訪問的組件,它需要做的工作,沒有更多,這將創(chuàng)建一個非常安全的環(huán)境,使應(yīng)用程序無法訪問的,這就是它沒有給予許可制度的部分。但是,有一個應(yīng)用程序的方法與其他應(yīng)用程序和應(yīng)用程序訪問系統(tǒng)服務(wù)的數(shù)據(jù):這有可能為兩個應(yīng)用程序安排共享相同的nux用戶ID,在這種情況下,它們能夠相互訪問的文件。為了節(jié)約使用相同的用戶ID系統(tǒng)資源,應(yīng)用程序還可以安排運(yùn)行在相同的nux進(jìn)程和共享同一個VM(應(yīng)用也必須使用相同的證書簽應(yīng)用程序可以請求訪問權(quán)限,如用戶的聯(lián)系人,短信,可安裝存儲(SD卡),攝像頭,藍(lán)牙等設(shè)備的數(shù)據(jù),所有應(yīng)用程序的權(quán)限必須由用戶在安裝時授予。這涵蓋了基本就如何oid應(yīng)用程序在系統(tǒng)中存在這個文件的其余部分向您介紹:·框架的核心組件定義應(yīng)用程序?!で鍐挝募新暶鹘M件和應(yīng)用程序所需的設(shè)備功能?!べY源是從應(yīng)用程序代碼分開,并允許您的應(yīng)用程序正常優(yōu)化的設(shè)備配置各種其行為。2.應(yīng)用程序組件oid的核心功能之一就是一個應(yīng)用程序可以使用其它應(yīng)用程序的元素(如果那個應(yīng)用程序允許的話)。比如說,如果你的應(yīng)用程序需要一個圖片卷動列表,而另一個應(yīng)用程序已經(jīng)開發(fā)了一個合用的而又允許別人使用的話,你可以直接調(diào)用那個卷動列表來完成工作,而不用自己再開發(fā)一個。你的應(yīng)用程序并沒有吸納或鏈接其它應(yīng)用程序的代碼,它只是在有需求的時候啟動了其它應(yīng)用程序的那個功能部分。為達(dá)到這個目的,系統(tǒng)必須在一個應(yīng)用程序的一部分被需要時啟動這個應(yīng)用程序,并將那個部分的Java對象實例化。與在其它系統(tǒng)上的應(yīng)用程序不同,Android應(yīng)用程序沒有為應(yīng)用準(zhǔn)備一個單獨的程序入口(比如說,沒有in()而是為系統(tǒng)依照需求實例化提供了基本的組件。共有四種組件類型:2.1活動一個activity代表用戶界面的一個獨立屏幕。例如,一個郵件應(yīng)用程序應(yīng)該有一個activity用于顯示新郵件列表,另一個activity用于撰寫一封郵件,還有一個activity用于讀取郵件。盡管所有activitie協(xié)同工作以構(gòu)成郵件應(yīng)用程序的用戶體驗,但彼此之間相對獨立。應(yīng)次,不同的應(yīng)用程序能夠從任何一個activity啟動(只要郵件應(yīng)用程序允許)。例如,用戶需要分享一張照片,一個拍照應(yīng)用程序能夠啟動郵件應(yīng)用程序的activity。activity是一個實現(xiàn)了tivity的子類,你可以在tivities開發(fā)者指導(dǎo)部分了解更多。2.2服務(wù)service是在后臺運(yùn)行,執(zhí)行長時間操作或者執(zhí)行遠(yuǎn)程操作。service不提供用戶界面。例如,當(dāng)用戶在另一個應(yīng)用程序時,一個service可在后臺播放音樂,或者是從網(wǎng)絡(luò)上獲取數(shù)據(jù),而不阻斷用戶與當(dāng)前activity的交互。其他組件,比如一個activity,為了與該service互動,可以啟動或者綁定它。service是一個實現(xiàn)了Service的子類,你可以在Services開發(fā)者指導(dǎo)部分了解更多。2.3廣播接收器廣播接收器是一個專注于接收廣播通知信息,并做出對應(yīng)處理的組件。很多廣播是源自于系統(tǒng)代碼的──比如,通知時區(qū)改變、電池電量低、拍攝了一張照片或者用戶改變了語言選項。應(yīng)用程序也可以進(jìn)行廣播──比如說,通知其它應(yīng)用程序一些數(shù)據(jù)下載完成并處于可用狀態(tài)。應(yīng)用程序可以擁有任意數(shù)量的廣播接收器以對所有它感興趣的通知信息予以響應(yīng)。所有的接收器均繼承自oadcastceiver基類。廣播接收器沒有用戶界面。然而,它們可以啟動一個activity來響應(yīng)它們收到的信息,或者用ificatinager來通知用戶。通知可以用很多種方式來吸引用戶的注意力──閃動背燈、震動、播放聲音等等。一般來說是在狀態(tài)欄上放一個持久的圖標(biāo),用戶可以打開它并獲取消息。2.4內(nèi)容提供者內(nèi)容提供者將一些特定的應(yīng)用程序數(shù)據(jù)供給其它應(yīng)用程序使用。數(shù)據(jù)可以存儲te數(shù)據(jù)庫或其它方式。內(nèi)容提供者繼承于entovider基類,為其它應(yīng)用程序取用和存儲它管理的數(shù)據(jù)實現(xiàn)了一套標(biāo)準(zhǔn)方法。然而,應(yīng)用程序并不直接調(diào)用這些方法,而是使用一個entsolver對象,調(diào)用它的方法作為替代。Contentsolver可以與任意內(nèi)容提供者進(jìn)行會話,與其合作來對所有相關(guān)交互通訊進(jìn)行管理。參閱獨立的內(nèi)容提供者entoviders章節(jié)獲得更多關(guān)于使用內(nèi)容提供者的內(nèi)容。每當(dāng)出現(xiàn)一個需要被特定組件處理的請求時,Android會確保那個組件的應(yīng)用程序進(jìn)程處于運(yùn)行狀態(tài),或在必要的時候啟動它。并確保那個相應(yīng)組件的實例的存在,必要時會創(chuàng)建那個實例。oid系統(tǒng)設(shè)計的一個獨特方面是任何的一個程序都可以啟動另一程序的組件。比如,你想讓你的程序可以使用照相機(jī)拍照,如果已經(jīng)有了實現(xiàn)這種功能的程序并且你你的程序能使用它(有權(quán)限),那么你就沒有再要再寫一個新的tivity來實現(xiàn)這個功能。你的程序不需要包含或者鏈接這個拍照程序。相反,你只需要在你的程序中打開這個拍照程序中的實現(xiàn)拍照功能的tivity。當(dāng)拍完之后,拍好的照片甚至?xí)詣臃祷亟o你的程序。者對于用戶來說,就好像是想拍照功能的程序就是你的這個程序的一部分一樣。當(dāng)系統(tǒng)啟動一個組件之后,如果這個組件所在的程序之前沒有運(yùn)行的話,系統(tǒng)會自動開始這個程序的進(jìn)程,并初始化這個組件所需要的相關(guān)類。比如,你的程序開啟了一個拍照功能程序的tivity,這時系統(tǒng)會啟動這個tivity所在的程序,所以這個tivity運(yùn)行在拍照功能的程序當(dāng)中,而不是在你的程序中。所以,不像其他操作系統(tǒng)的中的程序一樣,Android程序沒有一個單獨的入口點(比如沒有我們常見的in()函因為系統(tǒng)中的程序運(yùn)行在自己的獨立進(jìn)程中,并且程序中的文件都有自己的限制其他程序訪問的權(quán)限,所以,你的程序不能直接激活其他程序中的組件。但是oid系統(tǒng)就可以。具體是這樣的實現(xiàn)的,為了激活(activate)其他程序中的組件,你必須向系統(tǒng)發(fā)送一個消息來詳細(xì)說明你要啟動其他組件的意圖,這樣系統(tǒng)才會為你激活這個組件。3.激活組件四大組件中的三個組件——activities、services和broadcastreceiver——是由一種叫intent的異步消息來激活的。這些intents在運(yùn)行時(runti)將這些屬于你的程序或不同程序的單獨的組件綁定在一起(biintents看作是需要其他組件的action的ssengers。一個intent就是一個Intent對象,這個intent定義了一種可以激活(activate)某個特定組件或者某種特定類型的組件,這兩種情況分別對應(yīng)兩種intent的定義方式或者顯示的或者隱式的。對于activities和servicesintent定義了要執(zhí)行的操作(acti比如,要“view”或者“send”什么)和要操作的數(shù)據(jù)的。比如,一個intent可能會為一個activity傳遞一個請求來展示一張圖片或者打開一個網(wǎng)頁。有時,你可以啟動一個activity來得到返回的結(jié)果,在這個例子中這個activity的返回的結(jié)果也是一個Intent(比如,你可以發(fā)送一個intent讓用戶選擇一個personalcontact并返回給你——這個返回的intent就包含了一個指向用戶選擇的聯(lián)系人的I(關(guān)于activity和service的啟動方式,下面將介紹)對于廣播接收者來說,intent只是簡單的定義了要廣播的內(nèi)容(比如,一個用以表明電池電量很低的廣播僅包含了一個表明電池電量很低的字符串)。最后一種組件類型contentprovider并不是由intent來激活的(activate是由接收到entsolver的請求時激活的。它們都各自有自己的方法來激活相應(yīng)的組件:你可以通過傳遞一個Intent給starttivity()或starttivitysult()啟動一個activity(或者給他一些新的要做的內(nèi)容使用starttivitysult()你將得到一個返回結(jié)果。你可以通過傳遞一個Intent給startService()來start一個service(或者給一個正在運(yùn)行的service一些新的指令(instructions)個Intent傳遞給bindService()來綁定一個service。你可以通過傳遞一個Intent給諸如sendBroadcast()deredBroadcast()或者sendStickyoadcast()等方法來初始化一個廣播。你可以通過調(diào)用entsolver的query()方法來執(zhí)行一次contentprovider的查詢操作。更多的關(guān)于intent的內(nèi)容,可以參看文檔中的IntentsandIntentlters。更多的關(guān)于激活特定組件的內(nèi)容可以參看文檔中的:tivities、Services、oadcastceiver、Contentoviders。4. nifest文件在oid系統(tǒng)可以啟動一個應(yīng)用程序組件之前,Android系統(tǒng)必須通過讀取這個程序的oinifest.(即nifest文件)文件來確定要啟動的組件存在。你的程序必須在這個nifest文件聲明用到的所有的組件,并且這個nifest文件必須在項目的根目錄下。另外,這個nifest文件還聲明一些其他的東西,比如:確定這個程序需要的所有權(quán)限,比如Internet訪問權(quán)限或者讀取用戶聯(lián)系人權(quán)限。聲明這個運(yùn)行這個程序所需要的最低版本,這個可以根據(jù)開發(fā)該程序所使用的版本。聲明該程序所需要的硬件或軟件特征(features多點觸屏。聲明該程序需要鏈接(linkagainst)的庫(不是id的fraksepslibrary。等等。4.1組件聲明nifest文件的首要任務(wù)就是通知系統(tǒng)關(guān)于程序中要使用的組件。比如,一個nifest文件可以用如下圖4-1的方式來聲明一個activity:[java]viewplaincopy1. <?xml
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 期貨市場品牌建設(shè)與維護(hù)服務(wù)考核試卷
- 木材加工行業(yè)人才培養(yǎng)計劃考核試卷
- 攝影器材行業(yè)市場動態(tài)監(jiān)測與競爭情報分析考核試卷
- 辦公室員工職業(yè)發(fā)展與培訓(xùn)體系建設(shè)案例考核試卷
- 天然氣開采項目財務(wù)管理與成本控制考核試卷
- 固體飲料的無添加與天然成分趨勢考核試卷
- 木材貿(mào)易風(fēng)險管理與防范考核試卷
- 搪瓷衛(wèi)生潔具的顧客滿意度調(diào)查考核試卷
- 放射性金屬礦選礦實驗方法與技術(shù)考核試卷
- 鋼板出售轉(zhuǎn)讓合同范本
- 金庸人物課件
- 再生資源門店加盟協(xié)議書
- 療愈珠寶的科學(xué)與藝術(shù)
- 新能源汽車車位租賃合同
- 《人工智能導(dǎo)論》(第2版)高職全套教學(xué)課件
- 39 《出師表》對比閱讀-2024-2025中考語文文言文閱讀專項訓(xùn)練(含答案)
- 院前急救技術(shù)-止血包扎固定搬運(yùn)課件
- 中國煤炭地質(zhì)總局公開招聘報名表
- 電子商務(wù)數(shù)據(jù)分析基礎(chǔ)(第二版) 課件 模塊1、2 電子商務(wù)數(shù)據(jù)分析概述、基礎(chǔ)數(shù)據(jù)采集
- YB-T+4190-2018工程用機(jī)編鋼絲網(wǎng)及組合體
- 高大模板安全施工施工安全保證措施
評論
0/150
提交評論