看板 AndroidDev 關於我們 聯絡資訊
大概就是我在另開的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
sweet00914:這是個有趣的問題,因為-"背景無法控制前景"這規則。0. 02/14 23:08
sweet00914:前景(View),背景(Thread)。明天再來研究看看0.0 02/14 23:09
sweet00914:感謝原PO大大的分享0.0 02/14 23:09
k70430:試著改用AsyncTask看看,有幾個void能讓你改前景的 02/15 00:01