3

I am sending custom broadcasts from AppWidgetProvider class:

intent = new Intent();
intent.setAction("packagename.intent.action.SET_VOLUME_STATE");
context.sendBroadcast(intent);

and listening for them in BroadcastReceiver class:

public void onReceive(Context context, Intent intent) {
    if(intent.getAction().equals("packagename.intent.action.SET_VOLUME_STATE"))
    {
        //do stuff
    }
}

and have also registered the receiver with intent filter in manifest file. The problem is I am receiving the broadcast intent very late ~20-30 seconds after it is broadcast and sometimes it is sooner than that. I expect to receive the broadcast immediately and not lag behind. Am i missing something?

mukul
  • 171
  • 1
  • 15
  • Possible duplicated: http://stackoverflow.com/questions/20283440/broadcast-receiver-is-taking-too-long-to-receive-in-onreceive-after-airplane-m – zozelfelfo Sep 07 '15 at 06:29
  • If it is not required to send the broadcast system wide, then use local broadcasts: `LocalBroadcastManager.getInstance(context).sendBroadcast(intent);` instead of `context.sendBroadcast(intent);` – Ashkan Sarlak Sep 07 '15 at 06:32
  • Adding FLAG_RECEIVER_FOREGROUND to intent solved it. Thanks! – mukul Sep 07 '15 at 06:46

0 Answers0