Reputation: 11
I am using firebase real-time database for my app. It's great but I am facing a delay of some seconds during writing data from the app to firebase for the very first time. Means every time when I starts the app it takes a time of 2 seconds to send data to firebase. And after that it works fine with great speed. I know this isn't a big delay by any aspects but in my case I seriously needed the data transfer and fetching instantly. Is there any way to reduce this delay ? Thanks in advance.
Upvotes: 1
Views: 797
Reputation:
Reason: It is because at very first instance, firebase need to establish a connection between your app and firebase server. It will always delay by few seconds.
Solution: Establish a connection on app start. Once the first activity is loaded, establish a firebase connection inside onCreate()
of MainActivity.java or the other activity that gets loaded first.
Upvotes: 0
Reputation: 598797
The first time you access the Firebase Realtime Database from your code, the SDK has to establish a connection to the server. This involves multiple steps, which are only needed upon establishing the first connection. This explains why the first connection may take some time, and indeed it is not uncommon for it to take one of more seconds.
There is nothing you can do in code to improve the actual connection speed. That is up your bandwidth and latency (which I assume you're not interested in changing), and the SDK and server (which you can't change).
All you can do is start connecting as early as possible in your app's lifecycle, instead of waiting with it until you need to firs read/write data. For example, consider adding a listener to .info/connected
when your app first starts.
Upvotes: 1
Reputation: 3
True, hi vj Shandilya to my knowledge, the initial connection ought to take a tad longer than expected as this was the case while my team and I were working on an IoT based project linked with firebase and Android-Java.
Maybe you can add, a custom (not intense) progress animation to cover up for the 2 sec.
Upvotes: 0