Livedata returned by Room won't be triggered after GC

时间秒杀一切 提交于 2019-12-06 06:12:22

After post this issue to the google issue tracker(https://issuetracker.google.com/issues/114833188), I got reply:

We don't want to leak the LiveData if it is not used anymore. We could technically keep adding and removing the observer when LiveData is in use / not in use; but that might mean missing some events that happens when LiveData is inactive. We used to do that in the initial prototypes but became harder to maintain. You should keep a reference to the LiveData to keep using it. This is the patter we use in all examples.

So just keep a reference to the livedata returned by room instead of just observing it, everything works well now.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!