I want to know a method for download data saved into my Firebase database. For adding data into my firebase database, I use a push node so I can add multiple post for the same uid (user id). I saved successfully data into my database but I'm not able to download them. I've learned the firebase documentation and I know that I can use datasnapshoot but I don't know how to implement it on my code. Hope you can help me. Thank you.
Upload data into firebase database. I use this method which saves data in this format:
Data
- example-data
- uid
- key (push key generated by firebase)
- dataOne : dataOne
- dataTwo : dataTwo
..........code of the method .........................
private void addData(String dataOne, String dataTwo) {
final String key;
final String uid;
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
uid = user.getUid();
key = mDatabase.child("Data").push().getKey();
data data = new data(dataOne, dataTwo);
Map<String, Object> postValues = data.toMap();
Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put("Data" + "/example-data/" + uid + "/" + key, postValues);
mDatabase.updateChildren(childUpdates)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Intent intent = new Intent(Prova.this, Test.class);
startActivity(intent);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
}
Calling method addData for uploading by button:
public void buttonAddData(View view) {
String dataOne = mDataOne.getText().toString();
String urlSecondaImmagine = mDataTwo.getText().toString();
addData(dataOne, dataTwo);
}
This is the data class:
public class data {
public String dataOne;
public String dataTwo;
public data(){}
public data (String dataOne, String dataTwo){
this.dataOne = dataOne;
this.dataTwo = dataTwo;
}
public String getDataOne() {
return dataOne;
}
public String getDataTwo() {
return dataTwo;
}
@Exclude
public Map<String, Object> toMap() {
HashMap<String, Object> result = new HashMap<>();
result.put("dataOne", dataOne);
result.put("dataTwo", dataTwo);
return result;
}
}
My main task is to download these two data saved into my database. I need that these two data was displayed into other activity and displayed into a textview.
These two number: 9hiJ0YxyZXZnlrKFxv3jyhQlKUG2 LOca2YbV6Qb5q1RG1ws. First is ID of the user second is the push key generated by firebase database: