TheDeveloper
TheDeveloper

Reputation: 1217

Xamarin Insights for Android

I was wondering how can we monitor the crashes using xamarin insights for Android.

In iOS if we just add

Insights.Report(ex, Insights.Severity.Critical); in the main fun of the main class if does the trick.

Where should I add this code in android so I could capture all the crashes in Android?

Thanks.

Upvotes: 0

Views: 91

Answers (1)

SushiHangover
SushiHangover

Reputation: 74094

FYI: Insight is deprecated

But, when we were using it, normally would set it up in main Activity's OnCreate, something like:

protected override void OnCreate(global::Android.OS.Bundle bundle)
{
    Xamarin.Insights.Initialize(Keys.InsightsApiKey, this);
    AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
    {
        try
        {
            var ex = ((Exception)e.ExceptionObject).GetBaseException();
            Console.WriteLine("**SPORT MAIN ACTIVITY EXCEPTION**\n\n" + ex);
            Insights.Report(ex, Xamarin.Insights.Severity.Critical);
        }
        catch
        {
        }
    };
    ~~~~~~~
}

From the Xamarin Sport Example:

Ref: https://github.com/xamarin/Sport/blob/50b5896e17b86d88df53175fea5f4b1fa99b1164/Sport.Android/MainActivity.cs#L31

Upvotes: 1

Related Questions