Our xamarin app crashes sometimes with the following exceptions:
System.NotSupportedException: 'Unable to activate instance of type Xamarin.Forms.Platform.Android.FormsEditText from native handle 0xffce196c (key_handle 0xf8c2ea1).
System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.FormsEditText::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership).
Sadly this bug was not reproducible and only happens in production.
There is also a bug on github for this issue: https://github.com/xamarin/Xamarin.Forms/issues/13956.
CodePudding user response:
The workaround in our app looks like this.
public class CustomEntryRenderer : EntryRenderer
{
public CustomEntryRenderer(Context context) : base(context)
{
}
protected override FormsEditText CreateNativeControl()
{
return new CustomFormsEditText(Context);
}
}
public class CustomFormsEditText : FormsEditText
{
public CustomFormsEditText(Context context)
: base(context)
{
}
public CustomFormsEditText(System.IntPtr i, Android.Runtime.JniHandleOwnership j) : base(Forms.Context)
{
}
}