Forum Xamarin.Android

Mapping DoInBackground (C#) to doInBackground (Android)

I am trying to create a mapping solution for an existing in-house Android library using Xamarin Studio, and the mapping appeared to automatically work OK except for two compilation errors. I have two Android classes that in turn inherit from AsyncTask, and for both of these subclasses I was getting a mapping compilation error:

does not implement inherited abstract member 'Android.OS.AsyncTask.DoInBackground(params Java.Lang.Object[])

The Android classes themselves do implement that method, as:

Integer doInBackground(Void... voids){...}

The solution I came up with was to implement those two methods in C# Additions like so:

    partial class TaskOne {
            protected override  Java.Lang.Object DoInBackground (params Java.Lang.Object[] @params)
                return 0;

Which works in the sense that the compilation errors are gone, but seems "wrong" as obviously I would like the real implementation of this method to be executed and this code would seem to override them.

My reasoning for this mapping possibly working at runtime, was that no-one using the library would ever call DoInBackgroud (the C# version) and internally it would still use the real Android method from the library.

Is that thinking correct? Or, is there a better way to tell the system that the existing method really maps what it thinks it missing?

Thanks for any advice.


  • ColinPhillipsColinPhillips USMember

    Any update to this?

  • I think what you need is more to inherit from this class
    which allows you to define return types of the inherited methods
    be careful, when using this class, the doInBacground method becomes RunInBackground.
    This is an old post, but as I landed here, I answer, who knows you are still looking for a solution :smiley:

Sign In or Register to comment.