A method for waiting for sensor data

前端 未结 2 1731
不思量自难忘°
不思量自难忘° 2021-01-14 23:00

I have a class which initiates a sensor listener when it is started. This listener writes the latest sensor value to a variable when an event is triggered. The class goes on

2条回答
  •  臣服心动
    2021-01-14 23:41

    I am using Handler for exactly same situation.

    Handler handler = new Handler();
    handler.post(new Runnable() {
    
                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    try {
                        x1.setText(String.valueOf(sensors.getValueAccX()));
            Log.d("Sensors", String.valueOf(sensors.getValueAccZ()));//using persoanl methods that are not shown here
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (Exception e) {
                        Toast.makeText(ClientSideActivity.this,
                                "Server is not running", Toast.LENGTH_LONG).show();
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
    
                    // TODO Auto-generated method stub
    
                    handler.postDelayed(this, 100);
                }
    
            });
    

提交回复
热议问题