Dynamic Registration vs Static Registration of BroadcastReceiver

后端 未结 5 754
余生分开走
余生分开走 2021-01-01 14:18

All of us known we register BroadcastReceiver in two types

1)Static Registration

2)Dynamic Registration

B

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-01 14:48

    Easiest way decide is:

    If you want your App to listen the broadcast even if the App is closed Go for Static Broadcast Reciever.

    If you want your App to listen only for certain instance(When App is running) then go for Dynamic BroadCast Receiver.

    example:

    Any Battery monitoring App needs to listen to all broadcast intents(related to battery) even if App is not running. So here we need Static

    Any App that uses OTP, needs to listen to Sms only when App is running. Go for dynamic.

提交回复
热议问题