2013-05-18 29 views
0

有一種方法保護Long doInBackground(URL ... url){}。 URL ... urls的含義是什麼?Android AsyncTask Url

private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> { 
    protected Long doInBackground(URL... urls) { 
     int count = urls.length; 
     long totalSize = 0; 
     for (int i = 0; i < count; i++) { 
      totalSize += Downloader.downloadFile(urls[i]); 
      publishProgress((int) ((i/(float) count) * 100)); 
      // Escape early if cancel() is called 
      if (isCancelled()) break; 
     } 
     return totalSize; 
    } 

    protected void onProgressUpdate(Integer... progress) { 
     setProgressPercent(progress[0]); 
    } 

    protected void onPostExecute(Long result) { 
     showDialog("Downloaded " + result + " bytes"); 
    } 
} 

這些是從http://developer.android.com/reference/android/os/AsyncTask.html

回答

1

「類型......名字」語法的Java可變長度參數列表。它意味着零個或多個URL值。它們通過在方法中將URL(在本例中)視爲數組(URL [] url)進行引用。對於AsyncTask,您需要在.execute()方法中傳遞一個或多個URL:.execute(url1,url2,url3)。