박상권의 삽질블로그

Event bus [Bus "default"] accessed from non-main thread Looper 본문

IT/Android-ERROR&SOLVE

Event bus [Bus "default"] accessed from non-main thread Looper

박상권 2015. 11. 16. 19:15

안드로이드 개발자들이 모여있는 오픈채팅방에 참여해보세요 .
Q&A 및 팁을 공유하는 방입니다..
오픈채팅방 참여



블로그를 Medium으로 옮겨서 운영하고 있습니다.
앞으로 새로운 글은 모두 미디엄 블로그를 통해서 올릴 예정입니다.
미디엄에서 다양하고 유익한 포스팅을 살펴보세요
미디엄 블로그 보기


Otto를 사용하는경우 GCM을 위한 intentservice같은 곳곳에서 post를 보내는경우 오류가 발생할 수 있다.



Otto의 Bus클래스를 상속받아서 아래와같은 클래스를 만들고 이 클래스를 사용한다



public class CustomBus extends Bus {
private final Handler mHandler = new Handler(Looper.getMainLooper());

@Override
public void post(final Object event) {
if (Looper.myLooper() == Looper.getMainLooper()) {
super.post(event);
} else {
mHandler.post(new Runnable() {
@Override
public void run() {
CustomBus.super.post(event);
}
});
}
}

}


Comments