I faced to one problem on android 4.0.3 (on 4.1.2 it works fine). I have in my Activity BroadcastReceiver. When I send a broadcast, method onReceive() called always twice. P
I have just had this problem and I found a solution that wasn't mentioned in any of the existed answers, so I would like to share it.
I register the BroadcastReceiver just once in onCreate
However, I was registering it like this:
LocalBroadcastManager.getInstance(this).registerReceiver(new MyBroadcastReceiver(), mStatusIntentFilter);
In other words, I was constructing the boradcastReceiver instance inside the registerReceiver call.
But when I construct the BroadcastReceiver in a separate statement the problem was solved. Like this:
MyBroadcastReceiver myBroadcastReceiver = new MyBroadcastReceiver();
LocalBroadcastManager.getInstance(this).registerReceiver(myBroadcastReceiver , mStatusIntentFilter);
Very weird workaround, maybe it's a bug that will be fixed later.
Usually onReceive is being called twice since people are registering the broadcast in 2 locations,
Most likely you are registering in your onCreate and in your onResume.
(Choose one spot to register).
Although you might have done it probably a dozen of times - it is always recommended to take another glance at the Activity Life Cycle.
I was calling sendBroadcast(intent)
multiple times in my Service class
Removing one of them fixed the problem.