Q:

Android How to pass Firebase Database Reference to new activity

I have 3 buttons in my activity and Im looking for a way to pass database reference via onclick to new activity, so it loads content from Firebase Database depending on button pressed.
Something like this:

Button 1 pressed from Activity 1 > start Activity 2 & load data from Persons Reference > Person 1
Button 2 pressed from Activity 1 > start Activity 2 & load data from Persons Reference > Person 2
Button 3 pressed from Activity 1 > start Activity 2 & load data from Persons Reference > Person 3

I believe that I should use putExtra / getExtra to pass Intent. But how do I attach it to the specific node in Firebase Database inside new activity?

A:

I'd typically pass either the key/ID of the selected person, or the path of the node in the database by calling toString() on the DatabaseReference. Based on this information you then construct a new DatabaseReference to the same data in the new activity. DatabaseReference objects are really lightweight, so the overhead of creating a new one is minimal.
Neither if these approaches is pertinently better than the other, and both work in similar situations, so it's down to personal preference which one you use.

