重新启动应用程序或重新启动后,BroadcastReceiver无法接收

时间:2018-07-02 07:32:13

标签: android broadcastreceiver android-widget

我有一个AppWidget,在其中我的OnEnabled()方法中注册了BroadcastReceiver:

public void onEnabled(Context context){
    //Create the intent
    Intent sendIntent = new Intent(context, LightRowWidget.class);
    sendIntent.setAction(ACTION_APPWIDGET_UPDATE);

    // Get the ids
    AppWidgetManager manager = AppWidgetManager.getInstance(context);
    int[] ids = manager.getAppWidgetIds(new ComponentName(context, LightRowWidget.class));

    // set the broadcastReceiver
    NetworkReceiver mReceiver = new NetworkReceiver(sendIntent, ids);
    // Register it
    // Register the broadcast for connectivity change, which also receives disabling of a
    // widget.(if widget is disabled, broadcast will be unregistered).
    IntentFilter intentFilter = new IntentFilter();
    // add a filter
    intentFilter.addAction(widgetDisabled);
    intentFilter.addAction(connectivityChange);
    intentFilter.setPriority(Integer.MAX_VALUE);
    context.getApplicationContext()
            .registerReceiver(mReceiver,intentFilter);

这可能是什么原因?

0 个答案:

没有答案