如何检查 Firebase 应用是否已在 Android 上初始化
2022-08-31 10:57:41
在下面,第一次调用它时可以正常工作,但随后在后续调用中失败,并显示“FirebaseApp 名称 [DEFAULT] 已存在!
public FirebaseDatabase conn(Context c) {
FirebaseOptions options = new FirebaseOptions.Builder()
.setApiKey("key")
.setDatabaseUrl("url")
.setApplicationId("ID")
.build();
/////I tried Try and Catch with no success//////
FirebaseApp app = FirebaseApp.initializeApp(c, options);
/// for this : FirebaseApp app = FirebaseApp.initializeApp(c, options, "some_app");
//// will fail with "FirebaseApp name some_app already exists!"
return FirebaseDatabase.getInstance(app);
}
以上所有内容都是尝试连接到第二个 Firebase 应用。