Dynamic Registration vs Static Registration of BroadcastReceiver

Krishna picture Krishna · Apr 23, 2014 · Viewed 15.3k times · Source

All of us known we register BroadcastReceiver in two types

1)Static Registration

2)Dynamic Registration

But my doubt is when we need to use Static and when we need to use Dynamic?

Answer

Jitesh Upadhyay picture Jitesh Upadhyay · Apr 23, 2014

As we know there are two ways to register a BroadcastReceiver; one is static and the other dynamic.

Static:

  1. Use tag in your Manifest file. (AndroidManifest.xml)
  2. Not all events can be registered statically.
  3. Some events require permissions.

Dynamic:

  1. Use Context.registerReceiver() to dynamically register an instance.
  2. Note: Unregister when pausing.

When we are doing dynamic registration (i.e. at run time) it will be associated with lifecycle of the app. If we do it static registration (i.e. on compile time) and our app is not running, a new process will be created to handle the broadcast.