Skip to content

Instantly share code, notes, and snippets.

@fedefernandez
Created July 11, 2014 10:13
Show Gist options
  • Save fedefernandez/6803e6d98e84ddbba2e5 to your computer and use it in GitHub Desktop.
Save fedefernandez/6803e6d98e84ddbba2e5 to your computer and use it in GitHub Desktop.
Otto Bus that publish on UI thread
public class AndroidBus 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() {
AndroidBus.super.post(event);
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment