Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Mapping DoInBackground (C#) to doInBackground (Android)

$
0
0

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.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>