Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.4k views
in Technique[技术] by (71.8m points)

android - Firebase on app startup taking more than 3 seconds to load data

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 method

FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference();
Log.i("FIREBASE", "Before Firebase Call");
myRef.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        Log.i("FIREBASE", "Call Completed");
        // do my work i.e build my UI
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {
        Toast.makeText(context, "Please Check your Internet connection", Toast.LENGTH_LONG);
    }
});

Now my problem is, Firebase is taking more than 4 seconds getting the data. In the above code there is 4 seconds gap between both log statements i.e 'Before Firebase Call' & 'Call Completed'

I even tested in real devices, even there its taking minimum 3 seconds. Am I missing something here?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...