본문 바로가기

소프트웨어/Android/Java/Ndk

original thread that created a view hierarchy can touch its views

original thread that created a view hierarchy can touch its views

 

이 오류는

 

일반 thread에서 UI를 변경하려고 시도할때 나온다.

 

보통 onCreate에서 7초(맞나?)안에 ui작업을 끝내야해서 오래걸리는 작업은 thread로빼고 외부thread에서 UI를 건드릴때는runOnUIthread를 써야한다.

 

 

그 사실을 깜빡하고 ListView를 찍으면서 일반 thread를 썼는데 갤노트에서는 되던게 내 HTC에서는 안되던..

 

new Thread(new Runnable() { 
   public void run() {
    getList(root);
    endGetListMSG(handler);
   }
  }).start();

 

그래서 이렇게 썼던 소스를

runOnUiThread(new Runnable() {
   
   @Override
   public void run() {
    // TODO Auto-generated method stub
    getList(root);
    endGetListMSG(handler);
   }
  });

이렇게 바꿔서바로 해결.(runonuithread는 start를 안찍어도 지가 알아서 한다.