Fixed
Status Update
Comments
[Deleted User] <[Deleted User]> #2
Trying to find a temporary work-a-round I found that `MediatorLiveData` also doesn't work, as it internally also calls observeForever/removeObserver.
The only work-a-round I found is very hacky and only works on this specific scenario is to `post` to a Handler to `removeObserver` later.
It works only on this case because the background processing only happens when the network call is successful (a.k.a. the LiveData won't values anymore).
The only work-a-round I found is very hacky and only works on this specific scenario is to `post` to a Handler to `removeObserver` later.
It works only on this case because the background processing only happens when the network call is successful (a.k.a. the LiveData won't values anymore).
se...@google.com <se...@google.com> #3
Thank you for a report!
Yeah, your work around is fine for now. This is going to be fixed in alpha-9.
Yeah, your work around is fine for now. This is going to be fixed in alpha-9.
se...@google.com <se...@google.com> #4
Also, you can try go down to alpha-5, it may be fine there.
[Deleted User] <[Deleted User]> #5
hi "se...@google.com"
it seems that rolling back to alpha-5 solved it, and I'll be looking forward to alpha-9.
Is this bug brand new or something the team was already aware of?
thanks.
it seems that rolling back to alpha-5 solved it, and I'll be looking forward to alpha-9.
Is this bug brand new or something the team was already aware of?
thanks.
se...@google.com <se...@google.com> #6
No, we weren't aware of that. But we added tests for underlying issue.
[Deleted User] <[Deleted User]> #7
Great. Super happy to help!
Description
Version used: 1.0.0-alpha7
Devices/Android versions reproduced on: Nexus 6 (7.0 NBD92D), Emulator Nexus 4 API 25, and possibly any device
- Situation / Use case
App is using LiveData for network calls.
Activity queries the network observing on a newly created LiveData for that call
There is a background data processing that uses `observeForever` and `removeObserver` to observe ALL network calls generated by any activity.
Once called `removeObserver` from this background data processing the activity currently in foreground (resumed) does not receive the callback.
- Attached is a minimum example of it.
In the example:
The Application instantiates a BackgroundDataProcessing (that calls observeForever/removeObserver) that creates a list of the data and a BackgroundDataObserver that observes to the list of data and logs it.
The MainActivity queries the network LiveData that returns a result 1.5 seconds later. As a piece of automation to demo the bug, the MainActivity will start a new MainActivity in 3 seconds.
The BackgroundDataObserver always receives the value updates and the MainActivity never receives it. If comment out the line `source.removeObserver(this);` on the `BackgroundDataProcessing`, the MainActivity starts receiving those events (but we'll also be leaking memory)
I hope it helps.