[英]Cannot Intent to another activity
I was added buttonNext
then I set onClickListener
.我被添加了buttonNext
然后我设置了onClickListener
。 When the button is clicked and the barcode is the same as in firestore then the Intent to ViewData class, and the problem is when the button is clicked and the barcode is not the same as in firestore, it cannot be intent to AddItems
class.当单击按钮并且条形码与firestore中的条形码相同时,Intent to ViewData class,问题是当单击按钮并且条形码与firestore中的条形码不同时,它不能意图添加项目AddItems
。
Code:代码:
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 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()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.