I have my read-only data in firebase, It\'s about 50KB. And I need the complete data on app startup. For that I wrote the following code in my onCreate met
There is some overhead when establishing a connection for the first time. The connection is over a secure websocket, and in order to make sure it's secure, the there are multiple round trips between the client and the server required. If you are on a slow connection, particularly in a part of the world that is different than where the Firebase services happen to be hosted, it's very much possible to see some delay like this.
You can mitigate some of the delay by trying to read from the database as soon as the application launches rather than waiting for the first time data is required. That will kick off the websocket connection ASAP, so the perceived delay of the first real data request doesn't seem as extreme.
In my app, I use a loading screen (splash screen) to make sure all the required data is loaded before the app attempts to display any data. That also helps reduce the perceived load time.
As Doug Stevenson said: there should be a little delay when you're loading data for the first time, or if you're in a part of the world that is different than where the Firebase services happen to be hosted.
I suggest you create a loading screen (splash screen) to load all the data before showing your Main Activity.
In this Loading Activity, you can load all the data using the keepSynced
method:
FirebaseDatabase.getInstance().getReference().keepSynced(true);
This method will download your whole database to the disk cache. And when you show your Main Activity, FIrebase will load the data from this cache.
Generally, loading screens stay on screen for 1000-1500 milliseconds. But since you're saying the data takes 3 seconds, I recommend creating a loading screen that plays a 3000 milliseconds animation (or a set of animations that combined last 3000 milliseconds). If you don't know how to create animations, you can watch Chet Haase's DevBytes video.