1

I was using a firebase database in my Android app. Now I need to use another database but I want to know for the old versions of my app what will "firebaseDatabase.getInstance" return? Which database from my databases will be returned?

FirebaseDatabase.getInstance();
chetan mahajan
  • 349
  • 4
  • 15
Mostafa Khaled
  • 372
  • 4
  • 16
  • Retrieve an instance of your database using getInstance() and reference the location you want to write to. More information here : https://firebase.google.com/docs/database/android/start/ – chetan mahajan Nov 07 '18 at 12:58

1 Answers1

2

.getInstance() function actually gets a string of url as an input parameter. You can see it here.

Alternatively you can follow the tutorial here to actually create more than one instance in one app with manually setting FirebaseOptions, FirebaseApp and FirebaseDatabase objects.

// Manually configure Firebase Options
FirebaseOptions options = new FirebaseOptions.Builder()
        .setApplicationId("1:27992087142:android:ce3b6448250083d1") // Required for Analytics.
        .setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw") // Required for Auth.
        .setDatabaseUrl("https://myproject.firebaseio.com") // Required for RTDB.
        .build();

// Initialize with secondary app.
FirebaseApp.initializeApp(this /* Context */, options, "secondary");

// Retrieve secondary app.
FirebaseApp secondary = FirebaseApp.getInstance("secondary");
// Get the database for the other app.
FirebaseDatabase secondaryDatabase = FirebaseDatabase.getInstance(secondary);

Please also read the notes in the end, as using different databases might confuse your Google Analytics, causing analytics data drops.

koksalb
  • 430
  • 8
  • 14