0
votes

I only recently started learning Kotlin and using Firebase. I just had a few questions about the offline sync functionality. For context, the app I made, submits forms of information (mostly just booleans but I want to have images in the future too). I've got the offline part setup and have played around with it. I was just wondering:

  1. What happens if I close the app while there are still offline forms in the sync "queue".
  2. Are there limitations to this sync queue? e.g. size, amount of forms. Especially on the free plan for Firebase Realtime Database.

Here is the code I have written to do the offline syncing (used in a "private fun" for a setOnClickListener:

        val ref = FirebaseDatabase.getInstance().getReference("Inspections")

        ref.keepSynced(true)

        val fdbTubingId = ref.push().key

        val inspec = Inspection(ds, fdbTubingId.toString(), uniqueID, fac, ss, tid, fType,
                              Q1Aa, Q1Bb, Q1Cc, Q1CComment,
                              Q2Aa, Q2Bb, Q2Cc, Q2Dd, Q2CComment,
                              Q3Aa, Q3Bb, Q3CAa, Q3CBb, Q3CCc, Q3CComment,
                              Q4Aa, Q4Bb, Q4Cc, Q4Dd, Q4CComment,
                              Q5Aa, Q5Bb, Q5CComment,
                              Q6Aa, Q6CComment)

        if (fdbTubingId != null) {
            ref.child(fdbTubingId).setValue(inspec).addOnCompleteListener {
                Toast.makeText(applicationContext, "Inspection saved successfully", Toast.LENGTH_LONG).show()
            }
        }

Thanks.

1
Firebase has 18 products, including two databases. Which of these are you using? - Frank van Puffelen
Welcome to SO. A few things. 1) What @FrankvanPuffelen said. 2) Please limit questions to one question per question - otherwise it make make answers very very long, and mine are long enough as it is 3) This is a coding specific forum, so this there are still offline forms is quite vague as we don't know what your implementation is or where you're storing your forms to (it should be Firebase Storage which does not offer offline persistence). We really need to see some code that you're having difficulty with to really understand the use case. - Jay
Hi @FrankvanPuffelen I am using Firebase Realtime Database. - Tiuing Gum
Hi @Jay, thanks for the tip! I've edited the question so hope that helps. I'm not very good at Kotlin terms but the "forms" are just classes (in python terms) that consist of string and boolean arguments for editText and checkBox fields. Its the "val inspec" part of the code I have now added to the original post. - Tiuing Gum

1 Answers

0
votes

Firebase by default keeps the pending writes in memory only. In that configuration, any pending writes are lost when the app is closed.

If you enable disk persistence the pending writes (along with recently received data) are persisted to disk. In this situation, the pending writes are restored into memory when the app is restarted.

There is no documented or hard-coded limit on the number of pending writes. There's probably a physical limit, but it is not affected by the plan that you're on.


A final note: if you're asking this because you want to use Firebase as a semi-permanent offline database, I'd recommend against it. The number of pending writes linearly affects startup performance, and the size of the disk cache also affects memory consumption. You should really ensure that your Firebase clients can regularly synchronize data with the server. For a pure offline experience, you might want to consider databases that are better suited to that use-case.