Broadcast received immediately after subscribe
alexfjw opened this issue · comments
Not sure if its a bug, but the following observer seems to consistently fire a response immediately after I subscribe to it. Tested this on an emulator so I'm pretty sure it's not a connectivity issue.
IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); RxBroadcast.fromBroadcast(getContext(), filter).subscribe (.......)
I've set a flag in the subscriber to ignore this first response as a work-about, but it'll be nice to know if this first response thing is expected behavior. Perhaps I've unknowingly gone wrong somewhere. It works totally as expected after the first response though.
This is not an issue with the library. I believe this is more a result of Sticky broadcasts
It seems that if I were to expose isInitialStickyBroadcast that might work too. I don't think it's worth it for these cases.
Perhaps a more elegant solution for this particular case is to use .skip(1)
Ultimately though, I personally would shy away from this soon to be deprecated way of handling connectivity.
Apps targeting Android 7.0 (API level 24) and higher do not receive CONNECTIVITY_ACTION broadcasts if they declare their broadcast receiver in the manifest. Apps will still receive CONNECTIVITY_ACTION broadcasts if they register their BroadcastReceiver with Context.registerReceiver() and that context is still valid.
Yes technically we are still registering this in a valid context, so this doesn't directly apply, but I think you can see where this is going and there will be better ways to handle this... e.g., JobScheduler, etc