0
我點擊了一個按鈕(帶我到圖片庫以獲得結果)。當我選擇圖片時,我會很好地得到結果,然後使用獨立方法開始傳送圖像。Android,如何通過藍牙發送數據時更新用戶界面
問題是用戶界面卡在畫廊屏幕,然後屏幕變黑,直到傳輸完成...我嘗試更新用戶界面使用在UI上運行,但它不工作..
while ((bytesRead = bis.read(buf, 0, buf.length)) != -1)
{
BT_data_out.write(buf, 0, bytesRead);
if(fill++ > 2) {BT_data_out.flush(); fill = 0;};
prgrss += bytesRead;
final String done = Integer.toString(prgrss);
final String total = Integer.toString(fileL);
if(update_rate > (50000/bufSize)) {
update_rate = 0;
runOnUiThread(new Runnable()
{
@Override
public void run()
{
mTextMISC.setText(done+"/"+total+" B");
}
});
}
update_rate++;
}
一旦傳輸完成,我可以看到UI線程的最終效果,但所有中間更新從未見過。
你最好創建一個新的線程來傳輸數據;) – neohope