I am having two classes one is for uploading data, and other one is for retrieving data using addChildEventListener in firebase. My problem is when i upload the data its getting stored in database correctly. but as soon as i upload my data my childEventListener throwing null value. But when i manually add data to firebase database (website) am getting correctly.
Here is my uploading class
Firebase mref = new Firebase("https://social-a92cf.firebaseio.com/user");
Firebase create;
//name
create = mref.child(user+"_" + key_id).child("firstname");
create.setValue(profile_Name);
//date
create = mref.child(user+"_" + key_id).child("date");
create.setValue(date);
//place
create = mref.child(user+"_" + key_id).child("place");
create.setValue(place);
//description
create=mref.child(user+"_"+key_id).child("description");
create.setValue(description);
//imageurl
create = mref.child(user+"_" + key_id).child("url");
create.setValue(IMG_URL);
Toast.makeText(getApplicationContext(), "Uploaded",Toast.LENGTH_LONG).show();
My addChildEventListener
mref.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if(flag==1) {
ContactInfo ci = new ContactInfo();
if(dataSnapshot.child("url").getValue()!=null && dataSnapshot.child("firstname").getValue()!=null && dataSnapshot.child("description").getValue()!=null && dataSnapshot.child("place").getValue()!=null && dataSnapshot.child("date").getValue()!=null) {
ci.displayName = dataSnapshot.child("firstname").getValue().toString();
ci.displayDate = dataSnapshot.child("date").getValue().toString();
ci.description = dataSnapshot.child("description").getValue().toString();
ci.displayPlace = dataSnapshot.child("place").getValue().toString();
ci.imgUrl = dataSnapshot.child("url").getValue().toString();
list.add(ci);
ca.notifyDataSetChanged();
recList.smoothScrollToPosition(ca.getItemCount());
}
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Toast.makeText(getApplicationContext(),"Problem in loading feeds",Toast.LENGTH_LONG).show();
}
});
Can anyone help me how to solve this issue please.