Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get multiple app instances of Firestore in Firebase SDKs. More on multiple environments here:
FirebaseApp primary = FirebaseApp.getInstance();
FirebaseFirestore primaryDatabase = FirebaseFirestore.getInstance();
// Reference the same setup/instance
FirebaseOptions options = primary.getOptions();
// Use multiple projects/environments. More here:
FirebaseOptions options = new FirebaseOptions.Builder()
.setApplicationId("1:27992087142:android:ce3b6448250083d1") // Required for Analytics.
.setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw") // Required for Auth.
.setDatabaseUrl("") // Required for RTDB.
// 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.
FirebaseFirestore secondaryDatabase = FirebaseFirestore.getInstance(secondary);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.