To publish any thread (main or background) and get in the main thread, use MainThreadBus instead of Vanilla Bus
public class MainThreadBus extends Bus { private final Handler handler = new Handler(Looper.getMainLooper()); @Override public void post(final Object event) { if (Looper.myLooper() == Looper.getMainLooper()) { super.post(event); } else { handler.post(new Runnable() { @Override public void run() { MainThreadBus.super.post(event); } }); } } }
This is based on Andy Danny's answer.
There is no need to expand or wrap the Bus object, to do this or that. In Denny's answer, which is actually a wrapper, the Bus base class is used only as an interface, all functions are overwritten.
This would work even if you removed the base Bus class, unless you referenced MainThreadBus using the Bus link.
alexbirkett Feb 27 '14 at 9:13 2014-02-27 09:13
source share