-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 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This doesn't answer the question. using addValueEventValueListener also restarting activity every time there is an update in the db
The listener doesn't restart the activity, it seems that your case is different than the question's

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.