Xarmin.Android AsyncTask奇怪的行为

时间:2014-09-09 09:41:49

标签: java android android-asynctask

我必须实现我的Asynctask来实现一些工作。 这是我的代码:

class LoaderInfo : AsyncTask<Java.Lang.Void, Java.Lang.Void, Dictionary<String, String>>
    protected override void OnPreExecute()
    {
        base.OnPreExecute();
        //Set the dialog for the user.
        pDialog = new ProgressDialog(this.context);
        pDialog.SetMessage(message);
        //It means the "loading amount" is not measured.
        pDialog.Indeterminate = true;
        //Sets whether this dialog is cancelable with the BACK key.
        pDialog.SetCancelable(false);
        pDialog.Show();
    }
protected override Dictionary<String, String> RunInBackground(paramsJava.Lang.Void[] @params)
{
    Dictionary<String, String> d = new Dictionary<String, String>();
    return d;
}
protected override void OnPostExecute(Dictionary<String, String> result)
{
    base.OnPostExecute(result);
    this.pDialog.Dismiss();
}

问题是从不调用OnPostExecute! 我已经尝试过调试,但似乎是&#34; RunInBackground&#34; (在官方文档中我没有看到这种方法,但是visual studio告诉我,我必须实现这种覆盖方法,而不是DoInBackground,为什么?)并没有返回任何内容。

我尝试过这段代码,一切正常:

class LoaderInfo : AsyncTask<Java.Lang.Void, Java.Lang.Void, Java.Lang.Void>
{

ProgressDialog pDialog;
Context context;

public LoaderInfo(Context context)
{
    this.context = context;
}
protected override void OnPreExecute()
{
    base.OnPreExecute();
    //Set the dialog for the user.
    pDialog = new ProgressDialog(this.context);
    String message = this.context.GetString(Resource.String.load);
    pDialog.SetMessage(message);
    //It means the "loading amount" is not measured.
    pDialog.Indeterminate = true;
    //Sets whether this dialog is cancelable with the BACK key.
    pDialog.SetCancelable(false);
    pDialog.Show();
}
protected override void OnPostExecute(Java.Lang.Void result)
{
    System.Console.WriteLine("OnPostExecute");
    base.OnPostExecute(result);
    this.pDialog.Dismiss();
}

protected override Java.Lang.Void RunInBackground(params Java.Lang.Void[] @params)
{
    return null; 
}

} }

为什么我有这个问题?我做错了什么?

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

 protected override Void RunInBackground(params Void[] @params)
        {
            Java.Lang.Void jInt = null;
            return jInt;


        }