简体   繁体   中英

when should we use the OnCompleteListener() for queries

I am using firebase to develop a small app, I read that the Persistence(true) will queue the requests and execute them when the users have a connection. I put some codes in OnCompleteListener but they will not be executed when the users are offline and the data will become wrong when the users go online (after restarting the app ). so, should I move the codes out of OnCompleteListener() ? When should I use OnCompleteListener ?

And when I open the app again . the requests execute but the OnCompleteListener does not fire. anyone, please?

As you've found Firebase Realtime Database's OnCompleteListener s fire when the data has been written to the database on the server, and they are not persisted across app restarts.

I typically use OnCompleteListener to detect problems in writing, such as security rules rejecting the write operation.

You can also use OnCompleteListener to for example mark a messages as "delivered" to the database, but that requires some more work on your side to also handle the app restart scenario.

For example: writes of each client are executed in the order in which you call the API. So if you perform a token write when the app starts, and wait for the OnCompleteListener 's success of that one, you can be certain that writes that were submitted before the app restart have completed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM