In my app, I have an id that is supposed to be pulled down from firebase real time database. If I pull it down and it sees there is not an id available, then it sets the id
you need to set id = 1 into firebase database using setValue(), try below line of code it might help you
userRef.child("id").
addSingleValueEventListener(new ValueEventListener() {
@Override public void onDataChange (DataSnapshot dataSnapshot){
try {
String value = dataSnapshot.getValue().toString();
id = Integer.parseInt(value);
} catch (NullPointerException e) {
// if id=0 then set id=1 using setvalue()
// this will set value of Id =1 in firebase database
id=1;
userRef.child("id").setValue(id);
log.d(LOG_TAG, e.printStackTrace());
}
}
@Override public void onCancelled (DatabaseError databaseError){
id=1;
userRef.child("id").setValue(id);
}
});