问题
I've create android application in which we used Firestore database.
I want to update firebase document within time.
Firestore is quick to post on server but when there is any connection issue then it taking time to save on Firestore
My task is if User tried to update withing few seconds eg 20 seconds if user can't post that data on server withing 20 seconds then later on that update should not be post on server
If user is online and have good connection then there is no problem but if there is poor connection then it will create problem to me.
There was feasibility in realtime database but can't see in firestore
onDisconnectRef.cancel
I don't know how to manage this cancelation state but I've tried this code. It returning error that you can't do operation on running Firebase Instance Please suggest me what I need to do.
val hashMap = HashMap<String, Any>()
hashMap["status"] = "ACCEPTED"
hashMap["time"] = time
app().firestoreDB
.collection("doc")
.document("id")
.update(hashMap)
.addOnSuccessListener {
isStoredOnServer = true
// my action
}
object : CountDownTimer(20000, 1000) {
override fun onTick(millisUntilFinished: Long) {
if(isStoredOnServer){
this.cancel()
}
}
override fun onFinish() {
if(!isStoredOnServer) {
FirebaseFirestore.getInstance().clearPersistence()
.addOnFailureListener { e -> Log.d("Firestore", "Error persistence writing document $e") }
.addOnSuccessListener { Log.d("Could enable persistence:") }
}
}
}.start()
来源:https://stackoverflow.com/questions/63700993/how-to-restict-timely-manner-update-document-in-firestore-database-with-poor-net