外文翻译.docx
- 文档编号:16997397
- 上传时间:2023-07-21
- 格式:DOCX
- 页数:15
- 大小:25.34KB
外文翻译.docx
《外文翻译.docx》由会员分享,可在线阅读,更多相关《外文翻译.docx(15页珍藏版)》请在冰点文库上搜索。
外文翻译
本科生毕业设计(论文)
外文翻译
题 目手机防盗系统的设计与实现
姓 名
学 号
学 院 信息工程学院
专 业 计算机科学与技术
指导教师
2014年 4 月 10 日
原文:
BroadcastReceiver
publicabstractclass
BroadcastReceiver
extendsObject
java.lang.Object
↳android.content.BroadcastReceiver
KnownDirectSubclasses
AppWidgetProvider,DeviceAdminReceiver,WakefulBroadcastReceiver
ClassOverview
BaseclassforcodethatwillreceiveintentssentbysendBroadcast().
Ifyoudon'tneedtosendbroadcastsacrossapplications,considerusingthisclasswithLocalBroadcastManagerinsteadofthemoregeneralfacilitiesdescribedbelow.Thiswillgiveyouamuchmoreefficientimplementation(nocross-processcommunicationneeded)andallowyoutoavoidthinkingaboutanysecurityissuesrelatedtootherapplicationsbeingabletoreceiveorsendyourbroadcasts.
YoucaneitherdynamicallyregisteraninstanceofthisclasswithContext.registerReceiver()orstaticallypublishanimplementationthroughthe
Note:
IfregisteringareceiverinyourActivity.onResume()implementation,youshouldunregisteritinActivity.onPause().(Youwon'treceiveintentswhenpaused,andthiswillcutdownonunnecessarysystemoverhead).DonotunregisterinActivity.onSaveInstanceState(),becausethiswon'tbecallediftheusermovesbackinthehistorystack.
Therearetwomajorclassesofbroadcaststhatcanbereceived:
Normalbroadcasts(sentwithContext.sendBroadcast)arecompletelyasynchronous.Allreceiversofthebroadcastareruninanundefinedorder,oftenatthesametime.Thisismoreefficient,butmeansthatreceiverscannotusetheresultorabortAPIsincludedhere.
Orderedbroadcasts(sentwithContext.sendOrderedBroadcast)aredeliveredtoonereceiveratatime.Aseachreceiverexecutesinturn,itcanpropagatearesulttothenextreceiver,oritcancompletelyabortthebroadcastsothatitwon'tbepassedtootherreceivers.Theorderreceiversrunincanbecontrolledwiththeandroid:
priorityattributeofthematchingintent-filter;receiverswiththesameprioritywillberuninanarbitraryorder.
Eveninthecaseofnormalbroadcasts,thesystemmayinsomesituationsreverttodeliveringthebroadcastonereceiveratatime.Inparticular,forreceiversthatmayrequirethecreationofaprocess,onlyonewillberunatatimetoavoidoverloadingthesystemwithnewprocesses.Inthissituation,however,thenon-orderedsemanticshold:
thesereceiversstillcannotreturnresultsoraborttheirbroadcast.
Notethat,althoughtheIntentclassisusedforsendingandreceivingthesebroadcasts,theIntentbroadcastmechanismhereiscompletelyseparatefromIntentsthatareusedtostartActivitieswithContext.startActivity().ThereisnowayforaBroadcastReceivertoseeorcaptureIntentsusedwithstartActivity();likewise,whenyoubroadcastanIntent,youwillneverfindorstartanActivity.Thesetwooperationsaresemanticallyverydifferent:
startinganActivitywithanIntentisaforegroundoperationthatmodifieswhattheuseriscurrentlyinteractingwith;broadcastinganIntentisabackgroundoperationthattheuserisnotnormallyawareof.
TheBroadcastReceiverclass(whenlaunchedasacomponentthroughamanifest's
Security
ReceiverLifecycle
ProcessLifecycle
DeveloperGuides
Forinformationabouthowtousethisclasstoreceiveandresolveintents,readtheIntentsandIntentFiltersdeveloperguide.
Security
ReceiversusedwiththeContextAPIsarebytheirnatureacross-applicationfacility,soyoumustconsiderhowotherapplicationsmaybeabletoabuseyouruseofthem.Somethingstoconsiderare:
TheIntentnamespaceisglobal.MakesurethatIntentactionnamesandotherstringsarewritteninanamespaceyouown,orelseyoumayinadvertentlyconflictwithotherapplications.
WhenyouuseregisterReceiver(BroadcastReceiver,IntentFilter),anyapplicationmaysendbroadcaststothatregisteredreceiver.Youcancontrolwhocansendbroadcaststoitthroughpermissionsdescribedbelow.
Whenyoupublishareceiverinyourapplication'smanifestandspecifyintent-filtersforit,anyotherapplicationcansendbroadcaststoitregardlessofthefiltersyouspecify.Topreventothersfromsendingtoit,makeitunavailabletothemwithandroid:
exported="false".
WhenyouusesendBroadcast(Intent)orrelatedmethods,normallyanyotherapplicationcanreceivethesebroadcasts.Youcancontrolwhocanreceivesuchbroadcaststhroughpermissionsdescribedbelow.Alternatively,startingwithICE_CREAM_SANDWICH,youcanalsosafelyrestrictthebroadcasttoasingleapplicationwithIntent.setPackage
NoneoftheseissuesexistwhenusingLocalBroadcastManager,sinceintentsbroadcastitnevergooutsideofthecurrentprocess.
Accesspermissionscanbeenforcedbyeitherthesenderorreceiverofabroadcast.
Toenforceapermissionwhensending,yousupplyanon-nullpermissionargumenttosendBroadcast(Intent,String)orsendOrderedBroadcast(Intent,String,BroadcastReceiver,android.os.Handler,int,String,Bundle).Onlyreceiverswhohavebeengrantedthispermission(byrequestingitwiththe
Toenforceapermissionwhenreceiving,yousupplyanon-nullpermissionwhenregisteringyourreceiver--eitherwhencallingregisterReceiver(BroadcastReceiver,IntentFilter,String,android.os.Handler)orinthestatic
SeetheSecurityandPermissionsdocumentformoreinformationonpermissionsandsecurityingeneral.
ReceiverLifecycle
ABroadcastReceiverobjectisonlyvalidforthedurationofthecalltoonReceive(Context,Intent).Onceyourcodereturnsfromthisfunction,thesystemconsiderstheobjecttobefinishedandnolongeractive.
ThishasimportantrepercussionstowhatyoucandoinanonReceive(Context,Intent)implementation:
anythingthatrequiresasynchronousoperationisnotavailable,becauseyouwillneedtoreturnfromthefunctiontohandletheasynchronousoperation,butatthatpointtheBroadcastReceiverisnolongeractiveandthusthesystemisfreetokillitsprocessbeforetheasynchronousoperationcompletes.
Inparticular,youmaynotshowadialogorbindtoaservicefromwithinaBroadcastReceiver.Fortheformer,youshouldinsteadusetheNotificationManagerAPI.Forthelatter,youcanuseContext.startService()tosendacommandtotheservice.
ProcessLifecycle
AprocessthatiscurrentlyexecutingaBroadcastReceiver(thatis,currentlyrunningthecodeinitsonReceive(Context,Intent)method)isconsideredtobeaforegroundprocessandwillbekeptrunningbythesystemexceptundercasesofextremememorypressure.
OnceyoureturnfromonReceive(),theBroadcastReceiverisnolongeractive,anditshostingprocessisonlyasimportantasanyotherapplicationcomponentsthatarerunninginit.ThisisespeciallyimportantbecauseifthatprocesswasonlyhostingtheBroadcastReceiver(acommoncaseforapplicationsthattheuserhasneverornotrecentlyinteractedwith),thenuponreturningfromonReceive()thesystemwillconsideritsprocesstobeemptyandaggressivelykillitsothatresourcesareavailableforothermoreimportantprocesses.
PublicMethods
publicfinalvoidabortBroadcast()
Setstheflagindicatingthatthisreceivershouldabortthecurrentbroadcast;onlyworkswithbroadcastssentthroughContext.sendOrderedBroadcast.Thiswillpreventanyotherbroadcastreceiversfromreceivingthebroadcast.ItwillstillcallonReceive(Context,Intent)oftheBroadcastReceiverthatthecallerofContext.sendOrderedBroadcastpassedin.
publicfinalvoidclearAbortBroadcast()
Clearstheflagindicatingthatthisreceivershouldabortthecurrentbroadcast.
publicfinalbooleangetAbortBroadcast()
Returnstheflagindicatingwhetherornotthisreceivershouldabortthecurrentbroadcast.
publicfinalbooleangetDebugUnregister()
ReturnthelastvaluegiventosetDebugUnregister(boolean).
publicfinalintgetResultCode()
Retrievethecurrentresultcode,assetbythepreviousreceiver.
publicfinalStringgetResultData()
Retrievethecurrentresultdata,assetbythepreviousreceiver.Oftenthisisnull.
publicfinalBundlegetResultExtras(booleanmakeMap)
Retrievethecurrentresultextradata,assetbythepreviousreceiver.AnychangesyoumaketothereturnedMapwillbepropagatedtothenextreceiver.
publicfinalBroadcastReceiver.PendingResultgoAsync()
ThiscanbecalledbyanapplicationinonReceive(Context,Intent)toallowittokeepthebroadcastactiveafterreturningfromthatfunction.Thisdoesnotchangetheexpectationofbeingrelativelyresponsivetothebroadcast(finishingitwithin10s),butdoesallowtheimplementationtomoveworkrelatedtoitovertoanotherthreadtoavoidglitchingthemainUIthreadduetodiskIO.
Returns
ReturnsaBroadcastReceiver.PendingResultrepresentingtheresultoftheactivebroadcast.TheBroadcastRecorditselfisnolongeractive;alldataandotherinteractionmustgothroughBroadcastReceiver.PendingResultAPIs.ThePendingResult.finish()methodmustbecalledonceprocessingofthebroadcastisdone.
publicfinalbooleanisInitialStickyBroadcast()
Returnstrueifthereceiveriscurrentlyprocessingtheinitialvalueofastickybroadcast--thatis,thevaluethatwaslastbroadcastandiscurrentlyheldinthestickycache,sothisisnotdirectlythere
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 外文 翻译