簡體   English   中英

OnPostExecute永遠不會被調用

[英]OnPostExecute never gets called

我有一堂課,看起來像這樣:

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;
    }
}

其中AsyncTask屬於Android.OS

並發現從未執行過OnPostExecute

我還有其他一些類也從AsyncTask繼承(具體來說, AsyncTask<string, string, string> ,但是它們正常​​工作-即在需要時調用OnPostExecute

是什么原因造成的,如何解決?

檢查RunInBackground 此問題后 ,我懷疑這可能與RunInBackground返回.NET類型( List )有關。

更新

在弄亂了一些內容之后,我發現執行此操作的正確方法可能是定義以下兩種方法:

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

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

}

首先調用OnPostExecute(Java.Lang.Object result) ,然后將result傳遞到另一個OnPostExecute ,后者在某個時刻將Object轉換為所需的List


原始答案

因此,我添加了第二個OnPostExecute方法,該方法確實被調用:

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

}

在調試器中檢查result之后,我可以在Instance屬性中看到所需的值,現在可以使用以下屬性進行檢索:

var propertyInfo = result.GetType().GetProperty("Instance");
var newResult = 
    propertyInfo.GetValue(result, null) as List<List<Dictionary<string, string>>>;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM