2

I have a class which looks like this:

internal class MyClass
        : AsyncTask<string, int, List<List<Dictionary<string, string>>>>
{
    protected override void OnPostExecute(List<List<Dictionary<string, string>>> result)
    {

    }

    protected override List<List<Dictionary<string, string>>>
        RunInBackground(params string[] jsonData)
    {
        var routes = new List<List<Dictionary<string, string>>>();
        return routes;
    }
}

Where AsyncTask belongs to Android.OS

And find that OnPostExecute is never executed.

I have other classes which also inherit from AsyncTask (specifically, AsyncTask<string, string, string>, but these are working properly - i.e. OnPostExecute is called when expected.

What causes this, and how can I get around it?

Bassie
  • 9,529
  • 8
  • 68
  • 159

1 Answers1

3

After checking this question, I suspected this may have something to do with the fact that RunInBackground returns a .NET type (List).

Update

After messing around some more I found that this the right way to do this is probably to define the following 2 methods:

protected override void OnPostExecute(Java.Lang.Object result)
{
    base.OnPostExecute(result);
}

protected override void OnPostExecute(List<List<Dictionary<string, string>>> result)
{

}

Where OnPostExecute(Java.Lang.Object result) is called first, and passes result into the other OnPostExecute, which at some point converts Object to the required List.


Original Answer

So I added a second OnPostExecute method, which does get called:

protected override void OnPostExecute(Java.Lang.Object result)
{

}

After checking result in the debugger, I could see the values I needed in the Instance property, which I can now retrieve with:

var propertyInfo = result.GetType().GetProperty("Instance");
var newResult = 
    propertyInfo.GetValue(result, null) as List<List<Dictionary<string, string>>>;
Community
  • 1
  • 1
Bassie
  • 9,529
  • 8
  • 68
  • 159