Downloading multiple files simultaneously in Android applications

前端 未结 2 1034
予麋鹿
予麋鹿 2021-02-06 01:26

I\'m writing an application for Android which let users browse a list of files and download them. For every download, I created a thread and I download the file with an HttpURLC

2条回答
  •  攒了一身酷
    2021-02-06 01:56

    Alas, i don't know of a way to throttle certain connections. However, a practical approach would be to implement a queue of downloads to control the number of simultaneous downloads. In your case, you would probably want to only let 1 thing download at a time. This can be implemented a few different ways.

    Here's a way to do it with Handlers and a Looper: http://mindtherobot.com/blog/159/android-guts-intro-to-loopers-and-handlers/

    Edit 1: See mice's comment. It may be smarter to have a max of 2 threads downloading at a time.

提交回复
热议问题