我们为什么不注册BOOT_COMPLETED事件的广播接收器 [英] Why don't we register broadcast receiver for BOOT_COMPLETED events
问题描述
我感到困惑的这里的概念。我在很多教程阅读,为了当装置启动之后得到通知(说为目的的再调度报警),你需要有一个boot_completed广播接收机。
然而,令人困惑的是,没有在那里我看到像寄存器(boradcast接收器)的方法。人们只是有广播接收器类,他们有它明显。但不要你需要某种形式的注册流程?该系统将如何知道有一个X程序谁拥有广播接收者Y监听引导事件,除非通过注册
明确告知有点像你建立点击监听器,但你需要注册/它添加到按钮,使其能够顺利通过点击。叫
有人可以清除混乱给我吗?
感谢您
感谢
人们只是有广播接收器类,他们有它明显。但不要你需要某种形式的注册过程的?
块引用>的
<接收>
在清单元素具有<意向滤光器>
子元素,记录在意图
结构,它希望获得:<?XML版本=1.0编码=UTF-8&GT?;
<清单安卓版code =1
机器人:=的versionName1.0
包=com.commonsware.android.sysevents.boot
的xmlns:机器人=http://schemas.android.com/apk/res/android> <采用-SDK安卓的minSdkVersion =3
机器人:targetSdkVersion =6/>
<支持屏安卓largeScreens =假
机器人:normalScreens =真
机器人:smallScreens =FALSE/>
<使用许可权的android:NAME =android.permission.RECEIVE_BOOT_COMPLETED/>
<应用机器人:图标=@绘制/ CW
机器人:标签=@字符串/ APP_NAME>
<接收机器人:OnBootReceiverNAME =>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.BOOT_COMPLETED/>
&所述; /意图滤光器>
< /接收器>
< /用途>
< /清单>在这里,我们注册一个
广播接收器
,名为OnBootReceiver
,接受BOOT_COMPLETED
节目。
系统将如何知道有一个X程序谁拥有广播接收者Y监听引导事件,除非通过注册人明确告诉
块引用>Android是通过明确告知注册。碰巧的是,注册是通过清单进行,而不是通过在应用程序的Java code。
I am confused about the a concept here. I read on many tutorials that in order to get notified when device has booted (say for purpose of re-scheduling an alarm), you need to have a boot_completed broadcast receiver.
However the confusing part is that no where I see a method like "register(boradcast receiver)". People just have the broadcast receiver class and they have it in manifest. but dont you need some sort of registration process? How will the system know that there is an APP x who has a broadcast receiver y listening for boot events unless explicitly told through registering
Sort of like you create click listener, but you need to register/add it to the button to so it gets called upon clicked.
Can someone clear the confusion for me?
Thank you
Thanks
解决方案People just have the broadcast receiver class and they have it in manifest. but dont you need some sort of registration process?
The
<receiver>
element in the manifest has the<intent-filter>
child element, documenting theIntent
structure it wishes to receive:<?xml version="1.0" encoding="utf-8"?> <manifest android:versionCode="1" android:versionName="1.0" package="com.commonsware.android.sysevents.boot" xmlns:android="http://schemas.android.com/apk/res/android"> <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="6" /> <supports-screens android:largeScreens="false" android:normalScreens="true" android:smallScreens="false" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <application android:icon="@drawable/cw" android:label="@string/app_name"> <receiver android:name=".OnBootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> </application> </manifest>
Here, we are registering a
BroadcastReceiver
, namedOnBootReceiver
, to receiveBOOT_COMPLETED
broadcasts.How will the system know that there is an APP x who has a broadcast receiver y listening for boot events unless explicitly told through registering
Android is "explicitly told through registering". It just so happens that the "registering" is done via the manifest, not via Java code in the app.
这篇关于我们为什么不注册BOOT_COMPLETED事件的广播接收器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!