根據官方文件,這樣做並不是一個好方法。 http://developer.android.com/reference/android/app/DownloadManager.html
我會建議啓動一個服務或某種後臺線程,每隔幾秒查詢下載的狀態。 (保持在一個長[]跟蹤它們的ID,因爲setFilterById需要很長的[])
long[] ids = new long[MyDownloadQueue.length];
// Look at all these requests I'm building!
ids[i++] = dm.enqueue(request);
Cursor cursor = dm.query(new DownloadManager.Query().setFilterById(ids));
while (cursor.moveToNext()) {
int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
int status = cursor.getInt(columnIndex);
int columnReason = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
int reason = cursor.getInt(columnReason);
// your stuff here, recording the status and reason to some in memory map
}
這樣,你的列表視圖不會做任何的工作和UI將保持平穩。然而,我並不知道更好的方法,對不起,我無法提供不涉及查詢的答案。