Saving Firebase ref across multiple activities - Android

908 views
Skip to first unread message

m1s...@ucsd.edu

unread,
May 15, 2016, 8:14:32 PM5/15/16
to Firebase Google Group
Hi guys,

I just started learning firebase and am unsure how to save a firebase reference across multiple activities. This would not be an issue if I did not need to Authenticate, but my program requires so. 

The first way I thought up was to use a public static variable will be a singular firebase reference

If I were to create a firebase reference on each activity, would I be able to pass through authData by intent? Is there a way to grab authData/token and authenticate the next activity's ref using a token or something?

How do you android developers do it? Thank you for your time!

Frank van Puffelen

unread,
May 16, 2016, 12:22:30 AM5/16/16
to Firebase Google Group
Firebase authentication is automatically persisted in SharedPreferences. So there is no need to try and pass a Firebase reference between activities or other components. 

If you create a new reference, it will automatically have the same authentication state. Just attach an AuthStateListener and you'll get the data in the new activity too. This doesn't require an extra roundtrip to the Firebase servers.

    puf
Reply all
Reply to author
Forward
0 new messages