看起来好像
AsyncTask.get()阻塞了来电线程,
AsyncTask.execute()没有.
您可能希望使用AsyncTask.get()测试您想要测试特定Web Service调用的测试用例,但不需要它们是异步的,并且您想要控制完成所需的时间.或者任何时候您想在测试套件中测试您的Web服务.
语法与execute相同:
private class DownloadFilesTask extends AsyncTask {
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));
}
return totalSize;
}
protected void onProgressUpdate(Integer... progress) {
setProgressPercent(progress[0]);
}
protected void onPostExecute(Long result) {
showDialog("Downloaded " + result + " bytes");
}
}
new DownloadFilesTask().get(5000, TimeUnit.MILLISECONDS);