我正在嘗試創建沒有活動/服務的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