박상권의 삽질블로그

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

제가 운영하고 있는 유튜브 채널 '개발자 테드박'에도 많은 관심 부탁드려요.
스타트업/개발자/IT 관련된 여러 영상을 올리고 있습니다.
영상보러가기



블로그를 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);
}
});
}
}

}


1 Comments
댓글쓰기 폼