How to get a string from a Firebase real-time database that contains a unique key… here is a solution to the problem.
How to get a string from a Firebase real-time database that contains a unique key
I want to get a string from it :
, but it has a unique parent key. How do I get a string from a database? I tried :
firebaseAuth = FirebaseAuth.getInstance();
fUID =firebaseAuth.getCurrentUser().getUid();
itemsUrl ="https://nextweaverproject.firebaseio.com/users/" + fUID ;
mDatabase = FirebaseDatabase.getInstance();
final DatabaseReference myRef = mDatabase.getReferenceFromUrl(itemsUrl);
myRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Map<String, Object> td = (HashMap<String,Object>) dataSnapshot.getValue();
List<Object> values = new ArrayList<Object>(td.values());
strFb = new ArrayList<String>();
strFb.add(values.get(0).toString());
strFb.add(urlLong);
Log.v("test"," " + strFb.get(strFb.size()-1));
}
But it returns all objects in the database.
Solution
You can use child
to get data from the database tree:
myRef.child("Scenes").child("Scene").(" ******").
(*****).addChildEventListener(new ChildEventListener() {
This way you should link your fields.
You can also use addValueEventListener, addListenerForSingleValueEvent
.
You can read them here:
https://firebase.google.com/docs/database/android/retrieve-data