Skip to content

Instantly share code, notes, and snippets.

@juanmendez
Created September 7, 2015 16:01
Show Gist options
  • Save juanmendez/4c891b2e028e5a5bcdb5 to your computer and use it in GitHub Desktop.
Save juanmendez/4c891b2e028e5a5bcdb5 to your computer and use it in GitHub Desktop.
package YOUR_PACKAGE;
import android.os.Handler;
import android.os.Looper;
import com.squareup.otto.Bus;
public class BusUtil
{
private static final Handler mainThread = new Handler(Looper.getMainLooper());
/**
* making sure your bus update goes into the main thread
* @see <a href="http://square.github.io/otto/" target="_blank">Otto</a>
**/
public static void postOnMain( final Bus bus, final Object event) {
mainThread.post(new Runnable() {
@Override
public void run() {
bus.post(event);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment