Reputation: 1106
I have tried searching but couldn't find the solution to this.
playerEvent = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
playerList = new ArrayList<>();
int i = 1;
for (DataSnapshot ds : dataSnapshot.getChildren()) {
i++;
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
playerQuery.addValueEventListener(playerEvent);
Every time when it's calling onDataChange
the activity is restarting itself.
I want to keep listing the data changes in the Firebase Db so could not use addListenerForSingleValueEvent
Upvotes: 0
Views: 101
Reputation: 67
Please use
addListenerForSingleValueEvent
instead of
addValueEventListener
addValueEventListener listens to all the changes you make in your database and the code that exist in addValueListener which is "startActivity" gets triggered . change it on all the activities in your app
Upvotes: 1