Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
import android.os.Handler;
import android.os.Looper;
import com.squareup.otto.Bus;
public class MainThreadBus extends Bus {
private final Handler mainThread = new Handler(Looper.getMainLooper());
@Override public void post(final Object event) {
if (Looper.myLooper() == Looper.getMainLooper()) {
super.post(event);
} else {
mainThread.post(new Runnable() {
@Override
public void run() {
post(event);
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment