看板 AndroidDev 關於我們 聯絡資訊
※ 引述《freedom74569 (莫急莫慌莫害怕)》之銘言: : https://www.ptt.cc/bbs/AndroidDev/M.1451090467.A.79A.html : 這是上次的問題, : 我有抓到問題了, : 我implements library然後使用裡面的fuction : //宣告ArrayList mDevices1 : public ArrayList<BluetoothDevice> mDevices1 = new ArrayList<BluetoothDevice>(); : //使用library function,還是這裡會做在library package裡面,這樣讓我取不到? : @Override : public void bluetoothDeviceListBeenRenewed(BluetoothList bluetoothList) { : //mDevices1 = bluetoothList; : mLeDevices1.addAll(bluetoothList); : // 這裡打印的出來mDevices01,而且bluelist確定有東西也有打印出來 : Log.e("mDevices1", String.valueOf(mLeDevices1)); : } : 我只有在這個function印得出來mDevices1, : 不過在如onCreate or 其他地方要拿來用, : 就拿不到mDevices1就為空的陣列 : 存不回去上面宣告的mDevices1那 : 我想問看看有什麼關鍵字! : 現在完全沒有方向... activity 生命一開始沒多久會call onCreate 我猜這時候你的bluetoothDeviceListBeenRenewed還沒有被call到 因為你的list在bluetoothDeviceListBeenRenewed裡面塞值的 在還沒call的時候執行onCreate要找list的值當然是抓不到東西 這個假設的前提是onCreate比bluetoothDeviceListBeenRenewed先執行 如果list是要做UI相關的可以用handler回去UIThread作事 不然直接在bluetoothDeviceListBeenRenewed裡作就可以了 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.120.183.130 ※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1451287855.A.A14.html
freedom74569: 感謝j大大,我有試著用UiThread做看看,不過還是 12/28 21:17
freedom74569: 沒有成功,我在試看看,感謝有給我一個方向,不然 12/28 21:18
freedom74569: 無頭蒼蠅一樣:) 12/28 21:18