【发布时间】:2021-12-03 11:02:19
【问题描述】:
基本上,我创建了一个 Android 应用程序,用户在其中充电,然后 Firestore 的值更改为新值,但如果 android 应用程序没有更改,则需要更改活动或重新启动应用程序,值已更新但我想要实时更新的值反映在 Android 应用中。
这是我的代码:
DocumentReference reference =
FirebaseFirestore.getInstance().collection("Users").document(mobile);
reference.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot snapshot = task.getResult();
if (snapshot.getString("Wallet") != null) {
String wallet = snapshot.getString("Wallet");
walletshow.setText(wallet); // This value was update in real time if his wallet changes to
} else { // 100₹ to 150₹ the user need to relaunch or change the activity to refresh the values
walletshow.setText("Activate your account !");
walletshow.setTextColor(Color.RED);
Log.d("LOGGER", "No such document");
}
} else {
Log.d("LOGGER", "get failed with ", task.getException());
walletshow.setText("Login Again");
}
}
});
就是这样
【问题讨论】:
标签: java android firebase google-cloud-platform google-cloud-firestore