I have to implement my Asynctask to implement some work. This is my code:
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();
}
The problem is that OnPostExecute is never called! I have tried with the debug, but seems that the "RunInBackground" (in the official documentation I didn't see this method, but visual studio say me that I must implement this override method and not DoInBackground, Why?) doesn't return nothing.
I have tried with this code and everything works:
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;
}
} }
Why I have this problem? I am I'm doing something wrong?
Thanks in advance for the help.
0 comments:
Post a Comment