2
votes

I am using the latest HockeyApp nuget package for xamarin to utilize Preseason. In the documentation for Preseason it states that I’ve got to put the following in my mainactivity for a native android application:

MetricsManager.register(this, getApplication());

I have used the following in my Xamarin Android Application:

MetricsManager.Register(Android.App.Application.Context, this.Application );

However i receive a very strange error and do not know how to fix it or if i am even calling the metrics manager appropriately.

Here is my code:

protected override void OnCreate(Bundle bundle)
{
    try
    {
        base.OnCreate(bundle);
        // Register the crash manager before Initializing the trace writer
        HockeyApp.CrashManager.Register(this, AppId);

        //Register to with the Update Manager
        HockeyApp.UpdateManager.Register(this, AppId);

        // Initialize the Trace Writer
        HockeyApp.TraceWriter.Initialize();

        // Wire up Unhandled Expcetion handler from Android
        AndroidEnvironment.UnhandledExceptionRaiser += (sender, args) =>
        {
            // Use the trace writer to log exceptions so HockeyApp finds them
            HockeyApp.TraceWriter.WriteTrace(args.Exception);
            args.Handled = true;
        };

        MetricsManager.Register(Android.App.Application.Context, new Android.App.Application());

        Xamarin.Forms.Forms.Init(this, bundle);

        LoadApplication(new App());
        CheckForCrashes();
        CheckForUpdates();
    }
    catch
    {

    }
}

private void CheckForCrashes()
{
    CrashManager.Register(this, AppId);
}

private void CheckForUpdates()
{
    //todo: Remove this for production!!
    UpdateManager.Register(this, AppId);
}

Here is the error:

at Xamarin.Forms.Platform.Android.FormsApplicationActivity.OnPrepareOptionsMenu (IMenu menu) [0x00000] in :0 at Android.App.Activity.n_OnPrepareOptionsMenu_Landroid_view_Menu_ (IntPtr jnienv, IntPtr native__this, IntPtr native_menu) [0x00011] in /Users/builder/data/lanes/3053/a94a03b5/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.App.Activity.cs:4301 at (wrapper dynamic-method) System.Object:0ea0564e-2a6f-481c-ab24-cf222ecfff78 (intptr,intptr,intptr)

1
is that the whole text of the error? Also, can you post the code where you call MetricsManager.Register ? - Giorgi
it is a null reference error but yes that is the minus including that fact that is all the error in it's entirety - ArbiterUnknown
Got it fixed. The binding to the nuget package was wrong. This is correct HockeyApp.Metrics.MetricsManager.Register(this, Application, AppSettings.HockeyAppAndroidAppID) - ArbiterUnknown
Why don't you post it as an answer so that it's helpful to others as well? - Giorgi

1 Answers

2
votes

The binding to the nuget package was wrong. This is correct HockeyApp.Metrics.MetricsManager.Register(this, Application, AppSettings.HockeyAppAndroidAppID)