Back to project page Teracast-Android.
The source code is released under:
Apache License
If you think the Android project Teracast-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.davidtpate.teracast.bus; /*from www .j a va 2 s. c om*/ import android.os.Handler; import android.os.Looper; import com.squareup.otto.Bus; /** * From this stackoverflow post: http://stackoverflow.com/a/15433353/1309304 */ public class MainThreadBus extends Bus { private final Bus mBus; private final Handler mHandler = new Handler(Looper.getMainLooper()); public MainThreadBus(final Bus bus) { if (bus == null) { throw new NullPointerException("Bus must not be null"); } mBus = bus; } @Override public void register(Object obj) { mBus.register(obj); } @Override public void unregister(Object obj) { mBus.unregister(obj); } @Override public void post(final Object event) { if (Looper.myLooper() == Looper.getMainLooper()) { mBus.post(event); } else { mHandler.post(new Runnable() { @Override public void run() { mBus.post(event); } }); } } }