Add operators to create Observables from BroadcastReceiver#1449
Conversation
it allows to listen global and local (with support LocalBroadcastManager) broadcasts
|
RxJava-pull-requests #1399 FAILURE |
|
cast @mttkay. There are no tests for OperatorBroadcastRegister yet, because Roboelectric seems to ignores calls |
There was a problem hiding this comment.
so one question I have about this is how it ties in with the Context life-cycle, e.g. for an Activity. Would I subscribe to the observable in onStart and unsubscribe on onStop (or other life-cycle pairs accordingly?)
There was a problem hiding this comment.
also, this would mean that the context might get destroyed, and only then we post the call to unsubscribe to the message looper. We should test on a real device if this leads to problems e.g. during rotation changes and other instances of context loss
There was a problem hiding this comment.
that said, any reason why we can't do the unsubscribe synchronously? I don't think calls to unregisterReceiver have to happen on any particular thread
There was a problem hiding this comment.
life-cycle management lies on the user. He/she must unsubscribe from observable (as with unregisterReceiver) to prevent context leak.
About unregistering in main thread you are right.
Just looked at the sources of unregisterReceiver. Probably there is no reason to unsubscribe in main thread.
|
This looks pretty good to me overall, would love to test it out. One suggestion I have: have you thought about using |
|
I thought about it, but it creates much more questions, and become not so clear.
|
|
RxJava-pull-requests #1400 SUCCESS |
|
The intent matching within robolectric was fixed not too long ago here: robolectric/robolectric#1162 |
|
@dpsm I was having another problem. However if i use |
|
Looks like there is still ongoing discussion here ... let me know when there is agreement on this being ready to merge. |
|
@Yarikx I looked into the robolectric implementation of the Application shadow (https://github.com/xtremelabs/robolectric/blob/master/src/main/java/com/xtremelabs/robolectric/shadows/ShadowApplication.java) and indeed it does not implement the call you use to register the receiver. With that said, the test you have in the pull request fails? Would you be interested in contributing to robolectric with a fix for it so the test can pass? |
|
Yes. I would like.
|
|
Actually I think it's already fixed in current version of robolectric (2.3) https://github.com/robolectric/robolectric/blob/afeb7321f3/src%2Fmain%2Fjava%2Forg%2Frobolectric%2Fshadows%2FShadowApplication.java, this project use 2.2. @mttkay: If I will add tests for OperatorBroadcast, will it be candidate to be merged? |
|
Sure. By the way, anyone having problems building under IntelliJ lately? Something must have changed w.r.t. Gradle dependency configs, since anything in |
|
Rebased it to #1528 |
wraps BroadcastReceiver with Observable. Can be used with gloabl broadcasts and with local (using LocalBroadcastManager)