레이블이 Can't create handler inside thread that has not called Looper.prepare()인 게시물을 표시합니다. 모든 게시물 표시
레이블이 Can't create handler inside thread that has not called Looper.prepare()인 게시물을 표시합니다. 모든 게시물 표시

2011년 11월 22일 화요일

Android - ProgressDialog 표시


private ProgressDialog progressDialog = ProgressDialog.show(context, "", "Please wait...", true, false);


new Thread() {
    public void run() {
    //시간이 오래걸리는 작업

     //Intent i = new Intent(context,ActivitySubject.class);
//context.startActivity(i);

        handler.sendEmptyMessage(0);
    }
}.start();




private Handler handler = new Handler() {
    public void handleMessage(Message msg) {
        loagindDialog.dismiss();
        // View갱신
    }
};


화면(View) 와 관련된 코딩(다이얼로그의 호출과 같은)은 Hanlder를 이용해야 한다.

그렇지 않으면

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

에러가 발생된다.