본문 바로가기

프로그래밍/안드로이드

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

반응형

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


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


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


I believe this snippet of code constructs a Handler associated with the main (UI) thread:

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

You can then post stuff for execution in the main (UI) thread like so:

handler.post(something_to_run_on_main_thread);

반응형