Question

When RoboGuice fires Event, where will my event callback be executed, in which thread? For example, I have an activity which has do(@Observes OnUpdateUiEvent e). I also have a background thread which fires new OnUpdateUiEvent("data"). So, my do() method will be executed in bg thread as I understood? What will be, if I annotate do() with @Background from AndroidAnnotations? Should preprocessor make call to do() in runInUiThread()?

If everything is right, I think this pattern will provide the easiest way of communicating between threads.

Était-ce utile?

La solution

As far as I can see here and there, you can specify the way threads should mix with events in RoboGuice, by using @Observes(EventThread.CURRENT), @Observes(EventThread.UI) or @Observes(EventThread.BACKGROUND).

The default is "CURRENT", which means that if you didn't specify anything, the event listening method will be executed in the same thread as the method receiving the event.

So yes, if you fire your event from a background thread, do() will be executed in a background thread.

If you add @Background on the do() method, then it will always be executed in a separate thread, different from the one where you fired the event.

If you're not sure, put a breakpoint and watch the thread names :-) .

Did that answer your question?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top