2014-02-13 48 views
-1

似乎這個類不工作,因爲它從不發佈進度。 onPostExecute實際工作。但這個班主要依靠progressUpdateAsyncTask不能在onProgressUpdate Android

class DoBackgroundStuff extends AsyncTask<String, Integer, String> { 

    @Override 
    protected String doInBackground(String... a) { 

     String rawContactsDl; 
     while(true) { 

      if (isFinished == true) { 
       backgroundStopped = true; 
       break; 
      } 

      //DO SOME STUFF 
      publishProgress(1); 

      try { 
       Thread.sleep(3000); 
      } catch (InterruptedException e) { 
       e.printStackTrace(); 
      } 
     } 
     return "done"; 
    } 

    protected void onProgressUpdate(int progress) { 
     Log.i("VERBOSE","onProgress " + progress); 
     adapter.notifyDataSetChanged(); 
    } 

    protected void onPostExecute(String result) { 
     Log.i("VERBOSE","onPosts " + result); 
     adapter.notifyDataSetChanged(); 
    } 

} 
+1

isFinished ==是真的嗎? – ElDuderino

+2

哦,男人!無限循環 –

回答

8

你onProgressUpdate應該看起來像:

protected void onProgressUpdate (Integer... values) 

始終使用@覆蓋趕上這樣的錯誤

5

onProgressUpdate()簽名是錯誤的。它應該是

protected void onProgressUpdate(Integer... progress) 
+0

你好..你能看到我的問題。 – Piyush

相關問題