2014-10-31 3 views
0

Xamarin Studio에서 Android 응용 프로그램을 만들고 있지만 OnPostExecute()이 실행되지 않습니다.AsyncTask (C#)에서 OnPostExecute가 실행되지 않았습니다.

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() 방법 : 다음 DoInBackground() 방법 내에서

,이이

protected override void OnPostExecute(AsyncTaskResult<bool, Error> result) { 
    System.Console.WriteLine("On post execute"); 
} 

난 그냥 AsyncTask.execute() 메소드를 호출하고 있습니다.

그리고,이 출력 무엇인지 추측 :

Done the task. 

어떻게? 더 중요한 것은 어떻게 해결할 수 있습니까?

+0

많은 사람들이 Xamarin Android 개발을 철저히 즐깁니다. 그런 의견을 말하지 마십시오. – DavidG

+0

-1이 나온 곳입니까? –

+0

좀 더 많은 코드를 보여줄 수 있습니까? 그 몇 줄을 감안할 때 말하기가 어렵습니다. –

답변

0

(여전히) 형식 매개 변수와 함께 작동하지 않는 이유를 모르겠습니다. Java.Lang.Object에 의해

public class YourTask : AsyncTask { ... } 

하고, 진행 중이거나 결과 매개 변수를 게시의 모든 항목을 대체 : 그러나, 사물이 작동하게하기 위해, 당신은 제네릭 부분을 제거해야

여기
protected override Java.Lang.Object DoInBackground(params Java.Lang.Object[] parms) { ... } 

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

가있다 작동하는 일반 AsyncTask 샘플. 나는 당신이 여전히 모든 관련 코드를 보여주지 않기 때문에 당신의 문제가 정확히 무엇인지 모른다. 즉, 재정의 OnPostExecute (AsyncTaskResult 결과)는 언뜻보기에 나에게 잘못되었습니다. 내 버전에서는 TResult를 parmater 유형 (int는 필자의 경우)으로 사용합니다.

public class MyTask: AsyncTask<string, int, int> 
    { 
     protected MyTask(IntPtr javaReference, JniHandleOwnership transfer) 
      : base(javaReference, transfer) 
     { 

     } 
     public MyTask() 
     { 

     } 

     protected override int RunInBackground(params string[] @params) 
     { 
      return 4; 
     } 

     protected override void OnPostExecute(int result) 
     { 
      System.Console.WriteLine("On post execute"); 
      base.OnPostExecute(result); 
     } 
    } 
관련 문제