Skip to content

Instantly share code, notes, and snippets.

@dermatthias
Last active December 30, 2015 05:49
Show Gist options
  • Save dermatthias/7785128 to your computer and use it in GitHub Desktop.
Save dermatthias/7785128 to your computer and use it in GitHub Desktop.
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