Android BroadcastReceiver onReceive() called twice on android 4.0

前端 未结 15 2334
梦谈多话
梦谈多话 2020-12-29 20:38

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

15条回答
  •  情书的邮戳
    2020-12-29 20:58

    For Xamarin developers:

    I had a similar problem and for me it was because I registered the broadcast receiver in two places, one somewhere in my codes:

    Android.App.Application.Context.RegisterReceiver(myReceiver, new IntentFilter("MY_INTENT_ACTION"));
    

    And the other via Attributes:

    [BroadcastReceiver(Enabled = true, Exported = true)]
    [IntentFilter(new[] { "MY_INTENT_ACTION" })]
    public class MyReceiver : BroadcastReceiver
    {
        public override void OnReceive(Context context, Intent intent)
        {
        }
    }
    

    I removed Attributes and the problem solved!

提交回复
热议问题