Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Android documentation about "AccessibilityStateChangeListenerCompat" abstract class says
This class was deprecated in API level 24.2.0.
Use AccessibilityManager.AccessibilityStateChangeListener directly instead of this listener.
AddAccessibilityStateChangeListener is expecting object which implements IAccessibilityStateChangeListener.
When I provided such object method AddAccessibilityStateChangeListener throws invalid cast exception.
After some fiddling I have found that when my listener inherits from AccessibilityStateChangeListenerCompat the method AddAccessibilityStateChangeListener start to work as expected. This behaviour happens on Android M.
providing that kind of listener gives error:
public class MyCustomListener: IAccessibilityStateChangeListener
providing that kind of listener is working ok
#pragma warning disable 618
public class MyCustomListener: AccessibilityManagerCompat.AccessibilityStateChangeListenerCompat, IAccessibilityStateChangeListener
#pragma warning restore 618
So either this is a bug in Android itself or there is something missing in xamarin.android.
This happens both on API 23 and API 25
Can you please provide a sample project demonstrating this behavior? I believe what you need is the following Interface:
Thus it should look something like this:
public class MyListener : Java.Lang.Object, AccessibilityManager.IAccessibilityStateChangeListener
public void OnAccessibilityStateChanged(bool enabled)
throw new NotImplementedException();
Please also provide any error messages/exceptions so we can see what's going on. Feel free to upload these directly to the bug report and I will investigate further once we have a sample project. Thank you in advance for the report!
Doing it your way works perfectly. On the other hand documentation and compiler gives 0 clues what can be the problem.
(In reply to marcin.klimczak from comment #2)
> Doing it your way works perfectly. On the other hand documentation and
> compiler gives 0 clues what can be the problem.
We have added a helpful "fail faster" approach to this problem that you can view here: https://bugzilla.xamarin.com/show_bug.cgi?id=56819
Unfortunately it will not be included until 15.5. Hopefully this will help out your specific issue to let you know in the future when this build becomes available.
It's great that you have fixed it. Googling the issue wasn't giving any meaningfull results. Those small issues are having big impact on how developers perceive xamarin as a whole. People might think that xamarin is broken, where in fact it's only misunderstanding.