我有BroadcastReceiver(NetworkListener)。在手機重新啓動時取消廣播接收器。
public class NetworkReceiver extends BroadcastReceiver {
Context context;
public static NetworkReceiver instance = new NetworkReceiver();
public static InnerObservable observable = instance. new InnerObservable();
...
該接收器發送通知:
@Override
public void onReceive(Context ctx, Intent intent) {
Log.d("tag", "onReceive");
NotificationManager notif = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(android.R.drawable.ic_dialog_alert,"bla-bla-bla",System.currentTimeMillis());
清單文件:
<receiver
android:name="com.mypckg.network.NetworkReceiver" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
它工作正常。但是在電話重新啓動後,它會繼續工作。如何避免它?
我是否從清單中刪除接收者? –
是的,否則它仍然會在啓動時啓動 – fiddler
請注意,使用此解決方案時,廣播接收器將切換到其他活動時停止。如果你希望接收者的生命週期與應用程序的生命週期相同,那麼你應該在Application類中做到這一點 – fiddler