【发布时间】:2020-04-25 14:40:31
【问题描述】:
我的 Xamarin.Android 应用程序在模拟器中运行良好,但最近当用户在实际的 Android 设备上运行它时刚刚开始崩溃。 应用中心显示此错误:
FirebaseInstanceId.get_Instance() Java.Lang.IllegalStateException:默认 FirebaseApp 未在此进程“NameOfApp”中初始化。请务必先调用 FirebaseApp.initializeApp(Context)。
一些用户建议在我的 MainActivty.cs 文件中编辑我的 OnCreate 方法,添加这个 sn-p 代码:
Firebase.FirebaseApp.InitializeApp(this);
我已经这样做了,但我不想推出另一个损坏的应用程序。请让我知道这是否是解决此错误的正确方法,或者是否有其他方法可以解决。
感谢您的宝贵时间!
protected override void OnCreate(Bundle savedInstanceState)
{
Firebase.FirebaseApp.InitializeApp(this);
base.OnCreate(savedInstanceState);
if (!Parameter.CheckInternet())
{
Intent intent = new Intent(Application.Context, typeof(NoInternetActivity));
StartActivity(intent);
return;
}
Helper.TrackEvent(Parameter.CategoryLoad, "home", "Main");
if (Intent.Extras != null)
{
// If there is a Network error show message
if (Intent.Extras.ContainsKey("NetworkError"))
{
Toast.MakeText(this, "Network Error, please try again", ToastLength.Short).Show();
}
else
{
// If there is a link from a notification launch the appropriate activity
string linkType = Intent.GetStringExtra("LinkType");
string linkPage = Intent.GetStringExtra("LinkPage");
if (linkPage.Equals("main"))
{
// Link is a main page
LaunchMainActivity(linkType);
}
else
{
if (linkType.Equals("video"))
{
// Link is a Youtube video
Helper.LaunchVideo(this, linkPage);
}
else
{
// Link is a single page
LaunchSingleActivity(linkType, linkPage);
}
}
// Used this at some point to debug the extras but it's not necessary
foreach (var key in Intent.Extras.KeySet())
{
if (key != null)
{
var value = Intent.Extras.GetString(key);
Helper.TrackEvent("DEBUG", "extras", $"Key: {key} Value: {value}");
}
}
}
}
【问题讨论】:
标签: android firebase xamarin mobile xamarin.android