Skip to content

Instantly share code, notes, and snippets.

@alexshikov
Last active May 23, 2018 13:43
Show Gist options
  • Save alexshikov/ff8b522f7e8b55ec719f68e1765b0314 to your computer and use it in GitHub Desktop.
Save alexshikov/ff8b522f7e8b55ec719f68e1765b0314 to your computer and use it in GitHub Desktop.
Fix to NavigationPageRenderer constructor crash
using System;
using Android.Runtime;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android.AppCompat;
[assembly: ExportRenderer (typeof (NavigationPage), typeof (MyApp.Droid.Renderers.FixedNavigationRenderer))]
namespace MyApp.Droid.Renderers
{
// WARNING
// There is a crash happens for unknown reason:
// System.MissingMethodException: No constructor found for
// Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)
// see https://bugzilla.xamarin.com/show_bug.cgi?id=40258
// --
// As a solution we override NavigationPageRenderer to provide the constructor.
// Although then there is a NullReferenceException happens in
// OnDetachedFromWindow() method which we are fixing too.
public class FixedNavigationRenderer: NavigationPageRenderer
{
public FixedNavigationRenderer()
: base ()
{}
public FixedNavigationRenderer (IntPtr javaReference, JniHandleOwnership transfer)
: base ()
{
}
protected override void OnDetachedFromWindow ()
{
if (Element == null)
{
return;
}
base.OnDetachedFromWindow ();
}
}
}
@lassana
Copy link

lassana commented May 23, 2018

@midix have you managed to minimize total occurrences of such crashes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment