※ 引述《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裡作就可以了