Created
April 7, 2014 19:50
-
-
Save kevinmcmahon/10039798 to your computer and use it in GitHub Desktop.
AndroidBus
This file contains hidden or 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
| package com.example.common; | |
| import android.os.Handler; | |
| import android.os.Looper; | |
| import com.squareup.otto.Bus; | |
| 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