MustapTR
MustapTR

Reputation: 57

Complete download. (Firebase realtime)

I am downloading data from firebase realtime in my application. We download this data on the splashscreen. The splashscreen screen should not turn off before this data is downloaded. Couldn't find how to do this

This my code;

   mDatabase.child("/server/Time").addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            long time = dataSnapshot.getValue(Long.class);
            MyApplication.getInstance().setmServer(new server(time));
        }
        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {
            hideProgressDialog();
        }
    });

Upvotes: 0

Views: 152

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599081

If you only want to hide the splash screen once the data has been read from Firebase, you should put the code to hide it inside onDataChange. So:

mDatabase.child("/server/Time").addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        long time = dataSnapshot.getValue(Long.class);
        MyApplication.getInstance().setmServer(new server(time));
        hideProgressDialog();
        ... hide splash screen and perform other actions that depends on the data
    }
    @Override
    public void onCancelled(@NonNull DatabaseError databaseError) {
        hideProgressDialog();
    }
});

Also see:

Upvotes: 2

Related Questions