BroadcastReceiver receives multiple identical messages for one event

后端 未结 6 1391
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 11:10

I registered a receiver that listens to network events:



        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 12:11

    In my case, I was registering my BroadcastReceivers in onResume and only unregistering them in onDestroy.

    This caused each broadcastreceiver to be registered 3 or 4 times depending on how many times the activity resumes.

    Setting your broadcastreceiver in the right place in terms of the activity lifecycle will allow you to stop getting multiple confusing calls.

提交回复
热议问题