• 0
Votes
name

I'm trying to save the user details using a date as a unqiue id. I'm displaying the date on top which Ii get from a calendar view on another page.

I'm displaying the date on top which Ii get from a calendar view on another page.

I was wondering if I can use the date as a unique id to save other data inside it, and also use it read it when the time comes.

Currently, to write the data I'm using this code:

String id =databaseWorkouts.push().getKey();Workout workout =newWorkout(id, name, category );databaseWorkouts.child(id).setValue(workout);

What I see in your code is that you are using the push() method to generate that random unique key and you then you using it in the reference to add the object of Workout class to the database. You and not using the date as an identifier. Using push() method is a common practice when it comes Firebase. This random generated key provided by the this method is based on time. So, there is no need change this in any way.

  • 1
Reply Report