Made sure that downloads list is only modified on the UI thread
This commit is contained in:
parent
467ced31ee
commit
ffd1070270
|
@ -421,44 +421,14 @@ public class DownloadService extends Service {
|
|||
return null;
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public void onDownloadCompleted(final Downloader downloader) {
|
||||
final AsyncTask<Void, Void, Void> handlerTask = new AsyncTask<Void, Void, Void>() {
|
||||
boolean successful;
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
super.onPostExecute(result);
|
||||
if (!successful) {
|
||||
queryDownloads();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
removeDownload(downloader);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
handlerTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
handlerTask.execute();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove download from the DownloadRequester list and from the
|
||||
* DownloadService list.
|
||||
*/
|
||||
private void removeDownload(final Downloader d) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Removing downloader: "
|
||||
+ d.getDownloadRequest().getSource());
|
||||
|
@ -468,6 +438,8 @@ public class DownloadService extends Service {
|
|||
DownloadRequester.getInstance().removeDownload(d.getDownloadRequest());
|
||||
sendBroadcast(new Intent(ACTION_DOWNLOADS_CONTENT_CHANGED));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new DownloadStatus object to the list of completed downloads and
|
||||
|
|
Loading…
Reference in New Issue