0

I am posting a sticky event from an Activity, lets call this activity A. I successfully receive this event in Activity B. I go to Activity C and again come back to activity B as I come back the receive the same event which I received earlier. I understand that as I have posted a sticky event I have received it again, but how to work around this problem? I tried EventBus.getDefault().cancelEventDelivery(message); but it gives an error de.greenrobot.event.EventBusException: This method may only be called from inside event handling methods on the posting thread I put a log to check the Thread which was posting and receiving the event. Both show it as the main thread. Can anyone suggest some solution?

iZBasit
  • 1,314
  • 1
  • 15
  • 30

1 Answers1

0
  1. You can remove sticky event: Fallow documentation: https://github.com/greenrobot/EventBus/blob/master/HOWTO.md

    It's also possible to remove previously posted sticky events using one of the removeStickyEvent methods. They take either a concrete event object, or an event class. Like this it's possible to create consumable events. Keep in mind though that that only the last event of an event type is kept.

  2. idea is create your event consumable. Ex:

    public class SomeStivyEvent { 
        public void boolean consumed = false;  
    
        public void consumed(){
             consumed = true;
        } 
    } 
    
mariopce
  • 1,116
  • 9
  • 17