hehonghui / hehonghui/AndroidEventBus
弱引用带来的事件不触发问题
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.6k
- Forks
- 390
- PR merge metrics
- No merged PRs in 30d
Description
1.0.2版正常,在1.0.4版本以上时发现某些订阅方法无法接收到事件。
使用场景简述如下:
抽象类Alistener,包含订阅事件的方法method1,tag = “TAG1”,Alistener的实现类AAAlistener。
抽象类Blistener,包含订阅事件的方法method2,tag = “TAG2”,Blistener的实现类BBBlistener。
首先EventBus注册AAAlistener,当用户在UI触发事件“TAG1”,在AAAlistener的method1方法收到事件,在method1方法中EventBus注册new BBBlistener,接着弹出对话框让用户操作,完成之后发送“TAG2”事件;正常情况应该是BBBlistener的method2接收到这个事件,实际却没有接收到。
下载源码跟踪调试后发现在DefaultEventHandler的handleEvent方法调用时,应该执行BBBlistener.method2的时候,subscription.subscriber.get()却为null。目前并未深入研究,猜测是不是因为弱引用的AAAlistener被回收导致在其方法内new的BBBlistener也被回收?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at DefaultEventHandler.handleEvent and trace why subscription.subscriber.get() becomes null in the described TAG1-to-TAG2 sequence. Reproduce registering AAAlistener, creating BBBlistener inside method1, and sending TAG2 after the dialog; the issue is done when BBBlistener.method2 receives TAG2 reliably.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100