I want the children count in firebase to assign token. So I was used getChildren() method. This method gives the count and the count was incremented and assigned to each member. The problem raised when two users uses the application at a same time. For example, the children count was 10. If both the users uses the app at same time then both users get count of 10 and it increments gives 11. Hence both the users get token 11. If other user who was use the app after the above two, gets the correct number as 12 and it increments to 13 and 13 was assigned to that user.
databaseArtists.orderByChild("artistName").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) {
++ct;
Log.d("log", "onDataChange: " + dataSnapshot1.child("Appointment").child(bdate).child(session).child(docname).child("artistName").getValue());
}
});
Is there anyway to solve my problem?