该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
如题,现在我在内部类中,获取到一个值,我想把这个值传递到全局变量,但是全局变量的值,只在这个内部类的方法中才好用,到下一个方法,要使用的时候,就变成null了。那我应该如何获取到这个值呢。
//全局变量,blueListName
private String blueListName = null;
//一个内部类中的方法
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context,Intent intent) {
String action = intent.getAction();
// 获得已经搜索到的蓝牙设备
if (action.equals(BluetoothDevice.ACTION_FOUND)) {
BluetoothDevice device = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// 搜索到的不是已经绑定的蓝牙设备
if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
arrayList.add(device.getName());
for (int i = 0; i < arrayList.size()-1; i++)
{
for (int j = arrayList.size()-1; j > i; j--)
{
if (arrayList.get(j).equals(arrayList.get(i))) {
arrayList.remove(j);
// devices.add(j,device);
}
}
}
blueListName = arrayList.toString();
// 这里的blueListName是有值的,但是到下一个方法中再调用blueListName的时候,又为null, 就是没传递成功,那我该怎么获取到该值呢
Log.e(TAG, "AAAA=====" + blueListName);
// 显示在TextView上
tv_blue_name.setText("周围的蓝牙设备" + blueListName + "\n");
Log.e(TAG, "devicelist----" + blueListName.toString());
}
}
}
};