JeremyLiao / LiveEventBus

:mailbox_with_mail:EventBus for Android,消息总线,基于LiveData,具有生命周期感知能力,支持Sticky,支持AndroidX,支持跨进程,支持跨APP
Apache License 2.0
3.87k stars 529 forks source link

有办法清除之前发送的所有事件吗。 #73

Open getglory opened 5 years ago

getglory commented 5 years ago

支付结果使用observeSticky模式接收的(因为涉及到Activity可能被回收的问题),但是多个界面都有支付,这样就需要每个界面都增加一个flag,当该界面点击过支付的时候,才能允许接收事件,这样感觉非常麻烦,而且还会有其他的问题。。

JeremyLiao commented 5 years ago

暂时没有,会考虑这个需求

getglory commented 4 years ago

暂时没有,会考虑这个需求

建议添加类似谷歌的SingleLiveEvent的一次性事件功能:https://github.com/android/architecture-samples/blob/dev-todo-mvvm-live/todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/SingleLiveEvent.java 这样应该能解决问题

JeremyLiao commented 4 years ago

我想了一下,可能SingleLiveEvent并不能解决你的问题,SingleLiveEvent每次发送只会有一个Observer收到,这个Observer只会是第一个注册的Observer。我理了一下你的场景,可能这样能解决你的问题:假设你有A、B、C三个页面可能调支付,那么你在A注册Observer的时候你的key叫做“key_result_a”,同理,b,c,你调支付的时候把这个“key_result_a”通过bundle传给你的支付页面,支付成功之后你对这个key发送消息就可以了。