[問題] handler沒有回應
大概就是我在另開的thread改主線程的UI
GOOGLE找到解法 用handler去解
雖然存取UI thread是ok了
不過 因為會快速重覆執行handler
容易導致寫入的資料錯亂掉
public screenHandler screen_handler = new screenHandler();
public void print_screen(String tmp){
screen_txt = tmp;
Message m = new Message();
m.what = UPDATE_SETTING_SUCCESS;
screen_handler.sendMessage(m);
synchronized ( ???? ) {
try {
????.wait();
} catch (InterruptedException e) {
}
}
//msleep(30); 原本用sleep稍微delay的方式去解資料寫入錯亂問題 是ok
//但是覺得很笨
}
底下為handler
class screenHandler extends Handler {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case UPDATE_SETTING_SUCCESS:
TextView debug_screen = (TextView)findViewById( R.id.debug_screen );
debug_screen.setText( get_screen_txt ( screen_txt ) );
synchronized( ???? ) {
????.notify();
}
break;
}
super.handleMessage(msg);
}
}
有試在????的地方用this或是screen_handler去發送和接收來解鎖
但是都等不到notify的傳送 一值卡在wait()那邊
不知道正確的解法是怎樣?
很奇怪這解法我用在相機callback等待的情況下就ok....
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.69.90.23
推
02/14 23:08, , 1F
02/14 23:08, 1F
→
02/14 23:09, , 2F
02/14 23:09, 2F
→
02/14 23:09, , 3F
02/14 23:09, 3F
→
02/15 00:01, , 4F
02/15 00:01, 4F