Created
January 28, 2015 22:11
-
-
Save Aracem/f740240447da847903a2 to your computer and use it in GitHub Desktop.
OttoBus that always send Bus event in the main 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
/** | |
* 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