文献翻译.docx
《文献翻译.docx》由会员分享,可在线阅读,更多相关《文献翻译.docx(15页珍藏版)》请在冰点文库上搜索。
文献翻译
AndroidAPILevels
AsyoudevelopyourapplicationonAndroid,it'susefultounderstandtheplatform'sgeneralapproachtoAPIchangemanagement.It'salsoimportanttounderstandtheAPILevelidentifierandtheroleitplaysinensuringyourapplication'scompatibilitywithdevicesonwhichitmaybeinstalled.
ThesectionsbelowprovideinformationaboutAPILevelandhowitaffectsyourapplications.
Forinformationabouthowtousethe"FilterbyAPILevel"controlavailableintheAPIreferencedocumentation,see Filteringthedocumentation attheendofthisdocument.
WhatisAPILevel?
APILevelisanintegervaluethatuniquelyidentifiestheframeworkAPIrevisionofferedbyaversionoftheAndroidplatform.
TheAndroidplatformprovidesaframeworkAPIthatapplicationscanusetointeractwiththeunderlyingAndroidsystem.TheframeworkAPIconsistsof:
∙Acoresetofpackagesandclasses
∙AsetofXMLelementsandattributesfordeclaringamanifestfile
∙AsetofXMLelementsandattributesfordeclaringandaccessingresources
∙AsetofIntents
∙Asetofpermissionsthatapplicationscanrequest,aswellaspermissionenforcementsincludedinthesystem
EachsuccessiveversionoftheAndroidplatformcanincludeupdatestotheAndroidapplicationframeworkAPIthatitdelivers.
UpdatestotheframeworkAPIaredesignedsothatthenewAPIremainscompatiblewithearlierversionsoftheAPI.Thatis,mostchangesintheAPIareadditiveandintroduceneworreplacementfunctionality.AspartsoftheAPIareupgraded,theolderreplacedpartsaredeprecatedbutarenotremoved,sothatexistingapplicationscanstillusethem.Inaverysmallnumberofcases,partsoftheAPImaybemodifiedorremoved,althoughtypicallysuchchangesareonlyneededtoensureAPIrobustnessandapplicationorsystemsecurity.AllotherAPIpartsfromearlierrevisionsarecarriedforwardwithoutmodification.
TheframeworkAPIthatanAndroidplatformdeliversisspecifiedusinganintegeridentifiercalled"APILevel".EachAndroidplatformversionsupportsexactlyoneAPILevel,althoughsupportisimplicitforallearlierAPILevels(downtoAPILevel1).TheinitialreleaseoftheAndroidplatformprovidedAPILevel1andsubsequentreleaseshaveincrementedtheAPILevel.
ThefollowingtablespecifiestheAPILevelsupportedbyeachversionoftheAndroidplatform.
PlatformVersion
APILevel
Android3.0
11
Android2.3.3
10
Android2.3
9
Android2.2
8
Android2.1
7
Android2.0.1
6
Android2.0
5
Android1.6
4
Android1.5
3
Android1.1
2
Android1.0
1
UsesofAPILevelinAndroid
TheAPILevelidentifierservesakeyroleinensuringthebestpossibleexperienceforusersandapplicationdevelopers:
∙ItletstheAndroidplatformdescribethemaximumframeworkAPIrevisionthatitsupports
∙ItletsapplicationsdescribetheframeworkAPIrevisionthattheyrequire
∙Itletsthesystemnegotiatetheinstallationofapplicationsontheuser'sdevice,suchthatversion-incompatibleapplicationsarenotinstalled.
EachAndroidplatformversionstoresitsAPILevelidentifierinternally,intheAndroidsystemitself.
ApplicationscanuseamanifestelementprovidedbytheframeworkAPI— —todescribetheminimumandmaximumAPILevelsunderwhichtheyareabletorun,aswellasthepreferredAPILevelthattheyaredesignedtosupport.Theelementoffersthreekeyattributes:
∙android:
minSdkVersion —SpecifiestheminimumAPILevelonwhichtheapplicationisabletorun.Thedefaultvalueis"1".
∙android:
targetSdkVersion —SpecifiestheAPILevelonwhichtheapplicationisdesignedtorun.Insomecases,thisallowstheapplicationtousemanifestelementsorbehaviorsdefinedinthetargetAPILevel,ratherthanbeingrestrictedtousingonlythosedefinedfortheminimumAPILevel.
∙android:
maxSdkVersion —SpecifiesthemaximumAPILevelonwhichtheapplicationisabletorun. Important:
Pleasereadthe documentationbeforeusingthisattribute.
Forexample,tospecifytheminimumsystemAPILevelthatanapplicationrequiresinordertorun,theapplicationwouldincludeinitsmanifesta elementwitha android:
minSdkVersion attribute.Thevalueof android:
minSdkVersion wouldbetheintegercorrespondingtotheAPILeveloftheearliestversionoftheAndroidplatformunderwhichtheapplicationcanrun.
Whentheuserattemptstoinstallanapplication,orwhenrevalidatinganappplicationafterasystemupdate,theAndroidsystemfirstchecksthe attributesintheapplication'smanifestandcomparesthevaluesagainstitsowninternalAPILevel.Thesystemallowstheinstallationtobeginonlyiftheseconditionsaremet:
∙Ifa android:
minSdkVersion attributeisdeclared,itsvaluemustbelessthanorequaltothesystem'sAPILevelinteger.Ifnotdeclared,thesystemassumesthattheapplicationrequiresAPILevel1.
∙Ifa android:
maxSdkVersion attributeisdeclared,itsvaluemustbeequaltoorgreaterthanthesystem'sAPILevelinteger.Ifnotdeclared,thesystemassumesthattheapplicationhasnomaximumAPILevel.Pleasereadthe documentationformoreinformationabouthowthesystemhandlesthisattribute.
Whendeclaredinanapplication'smanifest,a elementmightlooklikethis:
minSdkVersion="5"/>
...
TheprincipalreasonthatanapplicationwoulddeclareanAPILevelin android:
minSdkVersion istotelltheAndroidsystemthatitisusingAPIsthatwere introduced intheAPILevelspecified.IftheapplicationweretobesomehowinstalledonaplatformwithalowerAPILevel,thenitwouldcrashatrun-timewhenittriedtoaccessAPIsthatdon'texist.ThesystempreventssuchanoutcomebynotallowingtheapplicationtobeinstalledifthelowestAPILevelitrequiresishigherthanthatoftheplatformversiononthetargetdevice.
Forexample,the android.appwidget packagewasintroducedwithAPILevel3.IfanapplicationusesthatAPI,itmustdeclarea android:
minSdkVersion attributewithavalueof"3".TheapplicationwillthenbeinstallableonplatformssuchasAndroid1.5(APILevel3)andAndroid1.6(APILevel4),butnotontheAndroid1.1(APILevel2)andAndroid1.0platforms(APILevel1).
Formoreinformationabouthowtospecifyanapplication'sAPILevelrequirements,seethe sectionofthemanifestfiledocumentation.
DevelopmentConsiderations
ThesectionsbelowprovideinformationrelatedtoAPIlevelthatyoushouldconsiderwhendevelopingyourapplication.
Applicationforwardcompatibility
Androidapplicationsaregenerallyforward-compatiblewithnewversionsoftheAndroidplatform.
BecausealmostallchangestotheframeworkAPIareadditive,anAndroidapplicationdevelopedusinganygivenversionoftheAPI(asspecifiedbyitsAPILevel)isforward-compatiblewithlaterversionsoftheAndroidplatformandhigherAPIlevels.TheapplicationshouldbeabletorunonalllaterversionsoftheAndroidplatform,exceptinisolatedcaseswheretheapplicationusesapartoftheAPIthatislaterremovedforsomereason.
ForwardcompatibilityisimportantbecausemanyAndroid-powereddevicesreceiveover-the-air(OTA)systemupdates.Theusermayinstallyourapplicationanduseitsuccessfully,thenlaterreceiveanOTAupdatetoanewversionoftheAndroidplatform.Oncetheupdateisinstalled,yourapplicationwillruninanewrun-timeversionoftheenvironment,butonethathastheAPIandsystemcapabilitiesthatyourapplicationdependson.
Insomecases,changes below theAPI,suchthoseintheunderlyingsystemitself,mayaffectyourapplicationwhenitisruninthenewenvironment.Forthatreasonit'simportantforyou,astheapplicationdeveloper,tounderstandhowtheapplicationwilllookandbehaveineachsystemenvironment.TohelpyoutestyourapplicationonvariousversionsoftheAndroidplatform,theAndroidSDKincludesmultipleplatformsthatyoucandownload.EachplatformincludesacompatiblesystemimagethatyoucanruninanAVD,totestyourapplication.
Applicationbackwardcompatibility
AndroidapplicationsarenotnecessarilybackwardcompatiblewithversionsoftheAndroidplatformolderthantheversionagainstwhichtheywerecompiled.
EachnewversionoftheAndroidplatformcanincludenewframeworkAPIs,suchasthosethatgiveapplicationsaccesstonewplatformcapabilitiesorreplaceexistingAPIparts.ThenewAPIsareaccessibletoapplicationswhenrunningonthenewplatformand,asmentionedabove,alsowhenrunningonlaterversionsoftheplatform,asspecifiedbyAPILevel.Conversely,becauseearlierversionsoftheplatformdonotincludethenewAPIs,applicationsthatusethenewAPIsareunabletorunonthoseplatforms.
Althoughit'sunlikelythatanAndroid-powereddevicewouldbedowngradedtoapreviousversionoftheplatform,it'simportanttorealizethattherearelikelytobemanydevicesinthefieldthatrunearlierversionsoftheplatform.EvenamongdevicesthatreceiveOTAupdates,somemightlagandmightnotreceiveanupdateforasignificantamountoftime.
SelectingaplatformversionandAPILevel
Whenyouaredevelopingyourapplication,youwillneedtochoosetheplatformversionagainstwhichyouwillcompiletheapplication.Ingeneral,youshouldcompileyourapplicationagainstthelowestpossibleversionoftheplatformthatyourapplicationcansupport.
Youcandeterminethelowestpossibleplatformversionbycompilingtheapplicationagainstsuccessivelylowerbuildtargets.Afteryoudeterminethelowestversion,youshouldcreateanAVDusingthecorrespondingplatformversion(andAPILevel)andfullytestyourapplication.Makesuretodeclarea a