Search code examples
androidbroadcastreceiverandroid-broadcastreceiver

Is a BroadcastReceiver's onReceive method always called the moment it gets registered dynamically?


I noticed that my wifi state BroadcastReceiver gets triggered everytime I register it in onResume with registerBroadcastReceiver. Is that the default behavior?


Solution

  • Some broadcasts are sticky. This means that they'll 'stick' around after being broadcast so that new receivers immediately receive them when they register.

    An intent that is used with sticky broadcast, is called as sticky intent. This intent will stick with android system for future broadcast receiver requests.

    See: https://stackoverflow.com/a/26038927/1810398