我正尝试通过查询 azure!来获取值!之后,我想尝试获取这些值并转移到新的意图,但是我不知道该怎么做,因为线程
在这里我开始puts
找到我需要的QrCode
id
这是我进行查询的地方,但是当我调用@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.qrcode_activity);
cameraPreview = findViewById(R.id.cameraPreview);
txtResult = findViewById(R.id.txtresult);
barcodeDetector = new BarcodeDetector.Builder(this).
setBarcodeFormats(Barcode.QR_CODE).build();
cameraSource = new CameraSource.Builder(getApplicationContext(), barcodeDetector)
.setRequestedPreviewSize(640, 480).build();
intent = new Intent(getBaseContext(), ValuesActivity.class);
barcodeDetector.setProcessor(new Detector.Processor<Barcode>() {
@Override
public void release() {
}
@Override
public void receiveDetections(Detector.Detections<Barcode> detections) {
final SparseArray<Barcode> qrcodes = detections.getDetectedItems();
if(qrcodes.size() != 0)
{
txtResult.post(new Runnable() {
@Override
public void run() {
//Create vibrate
Vibrator vibrator = (Vibrator)getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(100);
_idDevice = qrcodes.valueAt(0).displayValue;
txtResult.setText(qrcodes.valueAt(0).displayValue);
getQuery();
}
});
}
}
});
cameraPreview.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
ActivityCompat.requestPermissions(QrCodeActivity.this, new String[]{Manifest.permission.CAMERA},RequestCameraPermissionID);
return;
}
try {
cameraSource.start(cameraPreview.getHolder());
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
cameraSource.stop();
}
});
}
时,无法再次尝试从该线程访问变量。
如您所见:
runUIThread
答案 0 :(得分:1)
您没有指出不能访问哪些变量,因此我们必须弄清楚,但是您的问题不是它们在不同的线程中。它似乎与变量在不同范围内的可见性有关。如果所有内容都在同一个Activity中声明,那么在您发布的代码中访问它们应该没有任何问题,但是如果它们不在同一个类中,那么您就必须更改设计。
我唯一能看到的就是您在声明“ i”并尝试使用“ intent”:
Intent i = new Intent(getApplicationContext(),ValuesActivity.class);
intent.putExtra("id_equipamento", "Box2");
//intent.putExtra("listaValuesSensor", listaValuesSensor.get(coll.getId()).toString());
intent.putExtra("listaValuesSensor", listaValuesSensor);
intent.putExtra("dataValues", datasAlertas);