locked
How to make this Callback Handler work? RRS feed

  • Question

  • User244646 posted

    I have the following code: private Handler m_scraHandler = new Handler(new SCRAHandlerCallback());

    private class SCRAHandlerCallback : Java.Lang.Object, Handler.ICallback { public IntPtr Handle { get; private set; }

            public void Dispose()
            {
            }
    
            public bool HandleMessage(Message msg)
            {
                return true;
            }
    

    protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
    
            MTSCRA mtscrea = new MTSCRA(this, m_scraHandler);
        }
    

    For some reason when I run the application I would encounter the following error message: System.NotSupportedException: Unable to activate instance of type MagTekDriver.MainActivity+SCRAHandlerCallback from native handle 0xfffe6f7c (key_handle 0x8bc78cc).

    What is the cause of this error and how do I resolve it?

    Friday, March 31, 2017 12:44 AM

Answers

  • User12817 posted

    If you inherit from Java.Lang.Object, you shouldn't have to add your own implementation of Handler. I would guess this is where the issue is happening.

    It should really look like this:

    public class MyHandler : Java.Lang.Object, Handler.ICallback { public bool HandleMessage(Message msg) { throw new NotImplementedException(); } }

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, March 31, 2017 4:28 PM

All replies

  • User12817 posted

    If you inherit from Java.Lang.Object, you shouldn't have to add your own implementation of Handler. I would guess this is where the issue is happening.

    It should really look like this:

    public class MyHandler : Java.Lang.Object, Handler.ICallback { public bool HandleMessage(Message msg) { throw new NotImplementedException(); } }

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, March 31, 2017 4:28 PM
  • User244646 posted

    Thank you so much for your help again Jon, that solved my issue.

    Friday, March 31, 2017 4:35 PM
  • User386064 posted

    @JonDouglas said: If you inherit from Java.Lang.Object, you shouldn't have to add your own implementation of Handler. I would guess this is where the issue is happening.

    It should really look like this:

    public class MyHandler : Java.Lang.Object, Handler.ICallback { public bool HandleMessage(Message msg) { throw new NotImplementedException(); } }

    Hi, @JonDouglas when I try this, I get a ClassNotFoundException for MyHandler. I can stop this exception from happening by putting [Register("<CallBack Class>")] however the application proceeds to crash when the call back is registered. The error is Fatal signal 6 (SIGABRT), code -6 in tid 4396. I have spent the whole day trying different things, but to no avail.

    Tuesday, May 28, 2019 8:24 PM
  • User386064 posted

    Hi, I found my issue, I am using Xamarin Forms. I tried it in the Xamarin Android project and it worked fine.

    Wednesday, May 29, 2019 10:36 AM