我在Xamarin Studio中制作Android应用程序,但OnPostExecute()
未执行。OnPostExecute未在AsyncTask(C#)中执行
内DoInBackground()
方法,我有这样的:
protected override Java.Lang.Object DoInBackground(params Java.Lang.Object[] native_parms) {
System.IO.Stream ins = null;
try {
URL url = new URL(this.url);
HttpURLConnection conn = (HttpURLConnection) url.OpenConnection();
conn.ReadTimeout = 10000;
conn.ConnectTimeout = 15000;
conn.RequestMethod = "GET";
conn.DoInput = true;
conn.DoOutput = true;
Dictionary<string, string> queryParams = new Dictionary<string, string>();
queryParams.Add("username", this.username);
queryParams.Add("password", this.password);
System.IO.Stream os = conn.OutputStream;
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
// getQueryString() just builds a query string
writer.Write(getQueryString(queryParams));
writer.Flush();
writer.Close();
os.Close();
// Starts the query
conn.Connect();
int response = (int) conn.ResponseCode;
System.Console.WriteLine(response);
ins = conn.InputStream;
// Convert the InputStream into a string
String contentAsString = read(ins, conn.ContentLength);
System.Console.WriteLine("Done the task.");
return contentAsString;
// Makes sure that the InputStream is closed after the app is
// finished using it.
}
finally {
if (ins != null) {
ins.Close();
}
}
}
然后这是字面上的OnPostExecute()
方法:
protected override void OnPostExecute(AsyncTaskResult<bool, Error> result) {
System.Console.WriteLine("On post execute");
}
我打电话的AsyncTask.execute()
方法。
你猜怎么着,这是输出:
Done the task.
怎么来的?而且,更重要的是,我该如何解决它?
很多人充分享受Xamarin Android开发。请不要发表那样的意见。 – DavidG 2014-10-31 10:30:55
那是-1来自哪里? – 2014-10-31 10:42:00
你能告诉我们更多的代码吗?很难说这几条线。 – 2014-10-31 10:42:32