Last active
December 30, 2015 05:49
-
-
Save dermatthias/7785128 to your computer and use it in GitHub Desktop.
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
import android.os.Handler; | |
import android.os.Looper; | |
import com.squareup.otto.Bus; | |
public class MainThreadBus 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() { | |
post(event); | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment