Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android中执行线程后,如何拥有最新的变量?_Android_Multithreading_Bluetooth_Attributes_Touch Event - Fatal编程技术网

在Android中执行线程后,如何拥有最新的变量?

在Android中执行线程后,如何拥有最新的变量?,android,multithreading,bluetooth,attributes,touch-event,Android,Multithreading,Bluetooth,Attributes,Touch Event,我在Android应用程序中使用蓝牙,所以在onTouchEvent中,我运行startDiscovery。然后,在onReceive中,我更改一些属性的值。回到onTouchEvent,我使用System.sleep8000等待打印刚刚获得的值。 我可以看到,这些值都经过了很好的修改,但有一个调用gap。我的意思是,打印的是上一次调用onTouchEvent的值 您知道如何获取上次调用的实际值吗?多谢各位 找到蓝牙设备时调用的函数: public void onReceive(Context

我在Android应用程序中使用蓝牙,所以在onTouchEvent中,我运行startDiscovery。然后,在onReceive中,我更改一些属性的值。回到onTouchEvent,我使用System.sleep8000等待打印刚刚获得的值。 我可以看到,这些值都经过了很好的修改,但有一个调用gap。我的意思是,打印的是上一次调用onTouchEvent的值

您知道如何获取上次调用的实际值吗?多谢各位

找到蓝牙设备时调用的函数:

public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            amp = 0;
            name = null;

            if (device.getAddress().equals("00:11:22:33:44")) {
                amp = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, Short.MIN_VALUE);
                name = device.getName();
            }
        }
    }
在onTouchEvent中:

IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
            registerReceiver(mReceiver, filter);

            mBluetoothAdapter.startDiscovery();
            SystemClock.sleep(8000);

            print_RSSI(x, y);
在此之后调用以打印的函数:

private void print_RSSI(float x, float y) {

        RelativeLayout rl = (RelativeLayout) findViewById(R.id.Rel1);
        TextView tv;
        RelativeLayout.LayoutParams params;

        tv = new TextView(this);
        tv.setText(name + ":" + String.valueOf(amp));
        params = new RelativeLayout.LayoutParams(200, 40);
        params.leftMargin = (int) x;
        params.topMargin = (int) y;
        rl.addView(tv, params);
    }