Crash when going away from a page that is using IconLabel (Xamarin.Forms)
@jsmarcus I'm getting this crash when navigating away from a page (Xamarin.Forms 3.1) which is using an iconize control
Xamarin Exception Stack: System.NotSupportedException: Unable to activate instance of type Plugin.Iconize.IconLabelRenderer from native handle 0xbea8d29c (key_handle 0x9d32b5b). at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x0017d] in <263adecfa58f4c449f1ff56156d886fd>:0 at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000b9] in <263adecfa58f4c449f1ff56156d886fd>:0 at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <263adecfa58f4c449f1ff56156d886fd>:0 at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <263adecfa58f4c449f1ff56156d886fd>:0 at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in <263adecfa58f4c449f1ff56156d886fd>:0 at Android.Views.View.n_OnDetachedFromWindow (System.IntPtr jnienv, System.IntPtr native__this) [0x00000] in <263adecfa58f4c449f1ff56156d886fd>:0 at (wrapper dynamic-method) System.Object.6b050b03-6e3c-45a0-b69f-2d9f70535bf7(intptr,intptr) --- End of inner exception stack trace --- System.MissingMethodException: No constructor found for Plugin.Iconize.IconLabelRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00054] in <263adecfa58f4c449f1ff56156d886fd>:0 at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in <263adecfa58f4c449f1ff56156d886fd>:0 --- End of inner exception stack trace --- Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown. at Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown. at java.lang.Error: Java callstack: at md54e5d2a44c8aaca8b102b716ff166f806.IconLabelRenderer.n_onDetachedFromWindow(Native Method) at md54e5d2a44c8aaca8b102b716ff166f806.IconLabelRenderer.onDetachedFromWindow(IconLabelRenderer.java:54) at android.view.View.dispatchDetachedFromWindow(View.java:15564) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3187) at android.view.ViewGroup.removeAllViewsInLayout(ViewGroup.java:4910) at android.view.ViewGroup.removeAllViews(ViewGroup.java:4856) at md58432a647068b097f9637064b8985a5e0.FragmentContainer.n_onDestroyView(Native Method) at md58432a647068b097f9637064b8985a5e0.FragmentContainer.onDestroyView(FragmentContainer.java:41) at android.support.v4.app.Fragment.performDestroyView(Fragment.java:2497) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1503) at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750) at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:792) at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2590) at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2377) at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2239) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:700) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6186) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
I think the issue might be resolved by adding a constructor for IconLabel (in this case, might have to do for all the other controls as well) System.MissingMethodException: No constructor found for Plugin.Iconize.IconLabelRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)
somewhat like
public IconLabelRenderer(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) { }
same problem with you, it not compatible with XF 3.1
Same problem here. If someone have at least temporary fix I would like to know.
any new for update to fix problems ?
Hey guys, has anyone found a workaround for that problem?
I worked around the problem by writing my own IconLabelRenderer class just for android. And it worked. ` public class IconLabelRenderer : LabelRenderer { private CustomControls.IconLabel Label => Element as CustomControls.IconLabel;
public IconLabelRenderer(Context context)
: base(context)
{
// Intentionally left blank
}
public IconLabelRenderer(IntPtr javaReference, JniHandleOwnership transfer)
{ }
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
if (Label == null)
return;
UpdateText();
}
protected override void OnElementPropertyChanged(Object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (Label == null)
return;
switch (e.PropertyName)
{
case nameof(CustomControls.IconLabel.FontSize):
case nameof(CustomControls.IconLabel.TextColor):
UpdateText();
break;
}
}
protected override void OnAttachedToWindow()
{
base.OnAttachedToWindow();
if (Control != null)
Control.TextChanged += OnTextChanged;
}
protected override void OnDetachedFromWindow()
{
if (Control != null)
Control.TextChanged -= OnTextChanged;
base.OnDetachedFromWindow();
}
private void OnTextChanged(Object sender, Android.Text.TextChangedEventArgs e)
{
UpdateText();
}
private void UpdateText()
{
Control.TextChanged -= OnTextChanged;
var icon = Iconize.FindIconForKey(Label.Text);
if (icon != null)
{
Control.Text = $"{icon.Character}";
Control.Typeface = Iconize.FindModuleOf(icon).ToTypeface(Context);
}
Control.TextChanged += OnTextChanged;
}
}
`
The downside to this is that I cant use this for fast-renderers. And I havent tested this for fast renderers either.
@ninaada, I'll try your suggestion.
thanks a lot!