I noticed that my wifi state BroadcastReceiver gets triggered everytime I register it in onResume with registerBroadcastReceiver. Is that the default behavior?
Asked
Active
Viewed 194 times
1
Florian Walther
- 6,237
- 5
- 46
- 104
1 Answers
2
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.
Michael Powell
- 746
- 4
- 11
-
1You can check if the received broadcast is sticky: https://developer.android.com/reference/android/content/BroadcastReceiver.html#isInitialStickyBroadcast() – Robert Nekic Mar 06 '18 at 21:45
-
Oh, that is very interesting. Do you by any chance know if there is some sort of expiration or if it is safe to rely on this sticky broadcast to update my activity when I register my receiver in onResume? – Florian Walther Mar 06 '18 at 21:46
-
Oh I just noticed that onReceive is called even if I don't change the WiFi state while the app is in the background. So the sticky receiver doesn't seem to be the only reason? Or is that broadcast "always around"? – Florian Walther Mar 06 '18 at 21:51