In relational databases, I was using a uid column in each table as primary key. In Android code, I was using the following class format:
class A {
String uid;
// Other fields
}
I have switched to Firebase DB. I avoid using arrays while saving data to database, so everything is in key-value format, key being the push id created by calling push(). Since there is a key generated by Firebase, I instinctively assume that it is the counterpart for my uid field and I remove uid from the class. The database record seems as follows:
"-KonAikaef0Q0crP0AgK": {
// All fields of class A except 'uid' in key-value format
}
And class without uid seems as follows:
class B {
// All fields of class A except 'uid'
}
When I try to retrieve data from Firebase DB, I get DataSnapshot of key-value pairs, all values being an instance of class B. In some cases, I try to code as I did before, for example, I create a List<B>, populate it with values from resultant DataSnapshot, and give this list to an ArrayAdapter<B> to be shown in a ListView. Now, all keys are lost, which is crucial.
How can I overcome the problem I am facing?
- Should I keep
uidas seen here? - Should I keep dummy
uidfield and map key to this field manually at each retrieval? - Any other solution...