UI 쓰레드가 아닌 일반 쓰레드에서 UI 작업처리를 위해 new Handler() 를 통해 Handler를 사용할 경우 아래와 같은 에러가 발생합니다.


java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()


그럼 UI처리를 위한 Handler는 UI 쓰레드에서만 생성해야 한다고 생각할 수 있습니다.

http://huni.springnote.com/pages/5402287



그러나 그렇지 않습니다. 임의의 쓰레드에서도 UI작업용 Handler를 사용할 수 있습니다.

http://blog.naver.com/PostView.nhn?blogId=rgjoon&logNo=90094338577



다만, UI 작업을 처리하기 위해서는 아래와 같이 UI쓰레드에 바인딩된 Handler를 만들어야 합니다.

http://stackoverflow.com/questions/6369287/accessing-ui-thread-handler-from-a-service


Handler handler = new Handler(Looper.getMainLooper());




* 참고

http://www.aviyehuda.com/2010/12/android-multithreading-in-a-ui-environment/

http://babtingdev.tistory.com/276


Posted by 에코지오
,