Created
July 11, 2014 10:13
-
-
Save fedefernandez/6803e6d98e84ddbba2e5 to your computer and use it in GitHub Desktop.
Otto Bus that publish on UI thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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