我们为什么不注册BOOT

我们为什么不注册BOOT

本文介绍了我们为什么不注册BOOT_COMPLETED事件的广播接收器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我感到困惑的这里的概念。我在很多教程阅读,为了当装置启动之后得到通知(说为目的的再调度报警),你需要有一个boot_completed广播接收机。

然而,令人困惑的是,没有在那里我看到像寄存器(boradcast接收器)的方法。人们只是有广播接收器类,他们有它明显。但不要你需要某种形式的注册流程?该系统将如何知道有一个X程序谁拥有广播接收者Y监听引导事件,除非通过注册

明确告知

有点像你建立点击监听器,但你需要注册/它添加到按钮,使其能够顺利通过点击。叫

有人可以清除混乱给我吗?

感谢您

感谢


解决方案

The <receiver> element in the manifest has the <intent-filter> child element, documenting the Intent 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, named OnBootReceiver, to receive BOOT_COMPLETED broadcasts.

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事件的广播接收器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 02:07