Skip to content

Instantly share code, notes, and snippets.

@Aracem
Created January 28, 2015 22:11
Show Gist options
  • Save Aracem/f740240447da847903a2 to your computer and use it in GitHub Desktop.
Save Aracem/f740240447da847903a2 to your computer and use it in GitHub Desktop.
OttoBus that always send Bus event in the main thread
/**
* Upclose Otto library {@link com.squareup.otto.Bus}
*
*
* Created by Marcos Trujillo (U・x・U) on 28/07/14.
*/
public class OttoBus 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() {
UpcloseOttoBus.super.post(event);
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment