如何检查Firebase应用是否已在Android上初始化 [英] How to check if a Firebase App is already initialized on Android
本文介绍了如何检查Firebase应用是否已在Android上初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用以下命令,第一次将其称为有效,但随后会出现FirebaseApp name [DEFAULT]已存在的后续调用失败!
With the following, the first time it's called it works, but then fails on subsequent calls with "FirebaseApp name [DEFAULT] already exists!"
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应用。
All of the above is an attempt to connect to a second Firebase App.
推荐答案
在firebase网站上,您检查是否已经使用以下内容进行了初始化:
On firebase web, you check if already initialized with:
if (!firebase.apps.length) {
firebase.initializeApp({});
}
这篇关于如何检查Firebase应用是否已在Android上初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文