-1

I can get data from Firebird DataBase but they are updated only if I restart the activity how to do it without restarting the activity.

The code snippet with the implementation of retrieving data

 ValueEventListener valueEventListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

                long coinsAmount = dataSnapshot.child("coinsAmount").getValue(Long.class);
                text.setText(String.valueOf(coinsAmount));

        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {
            Log.d(TAG, databaseError.getMessage()); //Don't ignore errors!
        }
    };
    uidRef.addListenerForSingleValueEvent(valueEventListener);

1 Answers1

1

Change

uidRef.addListenerForSingleValueEvent(valueEventListener);

to:

uidRef.addValueEventListener(valueEventListener);

This way, your listener will be called each time the value in the DB changes, and not only once.

Read more about difference between valueEvent and singleValueEvent.

ronginat
  • 1,910
  • 1
  • 12
  • 23
  • This doesn't answer the question. using `addValueEventValueListener` also restarting activity every time there is an update in the db – Manoj ahirwar Dec 20 '20 at 11:55
  • The listener doesn't restart the activity, it seems that your case is different than the question's – ronginat Dec 20 '20 at 18:34