hehonghui / AndroidEventBus

A lightweight eventbus library for android, simplifies communication between Activities, Fragments, Threads, Services, etc.
Apache License 2.0
1.61k stars 392 forks source link

unregister 时有空指针问题 #19

Open jiantao88 opened 9 years ago

jiantao88 commented 9 years ago

移除注册事件时偶尔会发生空指针现象

jiantao88 commented 9 years ago

07-02 20:10:28.130 E/CrashReport(26443): android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3521) 07-02 20:10:28.130 E/CrashReport(26443): ...... 07-02 20:10:28.130 E/CrashReport(26443): cause by: 07-02 20:10:28.130 E/CrashReport(26443): java.lang.NullPointerException: 07-02 20:10:28.130 E/CrashReport(26443): org.simple.eventbus.SubsciberMethodHunter.removeMethodsFromMap(SubsciberMethodHunter.java:133) 07-02 20:10:28.130 E/CrashReport(26443): org.simple.eventbus.EventBus.unregister(EventBus.java:176)

hehonghui commented 9 years ago

@jiantao88 是最新版本对吗 ?你是在哪个时机注销的?

jiantao88 commented 9 years ago

是最新的版本,是在onDestory方法里

wurensen commented 9 years ago

确实可能会有这个问题,弱引用持有的订阅者,在没有判断不为null的情况下直接比较了

hehonghui commented 9 years ago

@wurensen 已经看到这个问题,周末处理一下。

hehonghui commented 9 years ago

已经处理了,各位可以看看。当引用对象为空时该Subscription也会被移除;不为空时则会跟传递进来的对象进行判等,如果相等也移除。

hehonghui commented 9 years ago

@jiantao88 @wurensen 你们都在产品中用了么 ?

andrewlu1 commented 8 years ago

我想知道能否去掉unregister这一步,能否实现自动取消订阅. 因为有很多场景并不存在成对的onCreate/onDestroy这样的操作的.

d0ng13 commented 8 years ago

@andrewlu1 可以考虑在onResume和onPause时刻去注册和注销