xamarin/Xamarin.Forms

"Animators may only be run on Looper threads" when raising ChangeCanExecute on Button command

Open

#4,964 opened on Jan 11, 2019

 (0 comments) (0 reactions) (0 assignees)C# (1,926 forks)batch import
e/5 :clock5:help wantedinactivep/Androidt/bug :bug:up-for-grabs

Repository metrics

Stars
 (5,644 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Found this bug on bugzilla that we are still experiencing in version 3.4.0.1009999 of Xamarin Forms.

"Animators may only be run on Looper threads" when raising ChangeCanExecute on Button command

Submitted by a community member on 2016-08-26 08:42 UTC

I have a view model with a command for a button. When I raise ChangeCanExecute method on Command the button flips from enabled to disabled, but I got a main thread exception.

I think the renderer should ensure things are done on the main thread, as that is touching the View element and it should not be the responsibility of the view model, IMHO.

System.Diagnostics.Debugger.Mono_UnhandledException_internal() in System.Diagnostics.Debugger.Mono_UnhandledException(Android.Util.AndroidRuntimeException ex) in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/corlib/System.Diagnostics/Debugger.cs:122 object.d54b8c39-4cf2-4565-8178-571c704bce52( arg0, arg1, arg2, arg3) in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 Java.Interop.JniEnvironment.InstanceMethods.CallVoidMethod(Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) in /Users/builder/data/lanes/3540/1cf254db/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:11643 Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(string encodedMember, Android.Support.V7.Widget.AppCompatButton self, Java.Interop.JniArgumentValue* parameters) in /Users/builder/data/lanes/3540/1cf254db/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:26 Android.Views.View.set_Enabled(bool value) in /Users/builder/data/lanes/3540/1cf254db/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:5198 Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer.UpdateEnabled() in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\ButtonRenderer.cs:234 Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer.OnElementPropertyChanged(Xamarin.Forms.Button sender, System.ComponentModel.PropertyChangedEventArgs e) in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\ButtonRenderer.cs:113 Xamarin.Forms.BindableObject.OnPropertyChanged(string propertyName) in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:137 Xamarin.Forms.Element.OnPropertyChanged(string propertyName) in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Element.cs:369 Xamarin.Forms.BindableObject.SetValueActual(Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject.BindablePropertyContext context, bool value, bool currentlyApplying, Xamarin.Forms.BindableObject.SetValueFlags attributes, bool silent) in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:581 Xamarin.Forms.BindableObject.SetValueCore(Xamarin.Forms.BindableProperty property, bool value, Xamarin.Forms.BindableObject.SetValueFlags attributes, Xamarin.Forms.BindableObject.SetValuePrivateFlags privateAttributes) in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:378 Xamarin.Forms.BindableObject.SetValueCore(Xamarin.Forms.BindableProperty property, bool value, Xamarin.Forms.BindableObject.SetValueFlags attributes) in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:324 Xamarin.Forms.Button.set_IsEnabledCore(bool value) in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Button.cs:112 Xamarin.Forms.Button.CommandCanExecuteChanged(Xamarin.Forms.Command sender, System.EventArgs eventArgs) in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Button.cs:172 Xamarin.Forms.Command.ChangeCanExecute() in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Command.cs:77


Reference: https://bugzilla.xamarin.com/show_bug.cgi?id=43782

Contributor guide