我正在尝试创建没有活动/服务的BroadcastReceiver。虽然当我在代码中存在活动时注册并执行代码时,我没有任何问题,但当我删除活动时它失败。如何在没有活动/服务的情况下创建BroadcastReceiver?
我使用清单(!)注册BroadcastReceiver但是当从项目中删除活动时不会调用它。
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver android:name="com.ge.test.InstallsListener" >
<intent-filter>
<data android:scheme="package" />
<action android:name="android.intent.action.PACKAGE_ADDED" android:priority="100"/>
</intent-filter>
</receiver>
</application>
谢谢。
在活动销毁之前,您必须取消注册接收方。因此,我认为你只能在Manifest中声明一个接收器。 –
完全阅读这个照顾http://developer.android.com/guide/components/fundamentals.html –
@ChristopheLongeanie:你绝对可以在清单中注册一个'BroadcastReceiver',在清单中只注册一个'BroadcastReceiver'。 – CommonsWare