gpt4 book ai didi

java - 不能 Intent 进行另一项 Activity

转载 作者:行者123 更新时间:2023-11-30 04:58:32 25 4
gpt4 key购买 nike

我被添加了buttonNext然后我设置 onClickListener .当单击按钮并且条形码与 firestore 中的相同时,然后 Intent 到 ViewData 类,问题是当单击按钮并且条形码与 firestore 中的条形码不同时,它不能 Intent AddItems类。

代码:

    collectionReference.whereEqualTo("barCode", scanResult).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot queryDocumentSnapshot : task.getResult()) {
if (queryDocumentSnapshot.getString("barCode") != null) { // Success intent to ViewData
collectionReference.document(queryDocumentSnapshot.getId()).update("productQuantity", FieldValue.increment(1));
Intent moveView = new Intent(ScannersActivity.this, ViewData.class);
moveView.putExtra("documentID", documentID);
startActivity(moveView);
finish();
} else { // Problem here..
Intent moveCode = new Intent(ScannersActivity.this, AddItems.class);
moveCode.putExtra("sendDocumentID", documentID);
moveCode.putExtra("ScanResult", scanResult);
startActivity(moveCode);
finish();
}
}
}
}
});

最佳答案

var isBarCodeAvailable = false

    for (queryDocumentSnapshot in task.getResult()) {
if (queryDocumentSnapshot.getString("barCode") != null) {
isBarCodeAvailable = true
break
} else {
isBarCodeAvailable = false
break
}
}

if (isBarCodeAvailable) {
collectionReference.document(queryDocumentSnapshot.getId())
.update("productQuantity", FieldValue.increment(1))
val moveView = Intent(this@ScannersActivity, ViewData::class.java)
moveView.putExtra("documentID", documentID)
startActivity(moveView)
finish()
} else {
val moveCode = Intent(this@ScannersActivity, AddItems::class.java)
moveCode.putExtra("sendDocumentID", documentID)
moveCode.putExtra("ScanResult", scanResult)
startActivity(moveCode)
finish()
}

关于java - 不能 Intent 进行另一项 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58706444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com