last day (14 days later) » 

9:54 AM
0
A: How to download multiple files concurrently using intentservice in Android?

mmlooloo to download multiple files asynchronously in Android. and also i think you want to download simultaneously. i think you misused the intentservice. intentservice has a looper and a handler and each call to start causes to create a message for the handler. all messages are queued in the loope...

 
Well, I have new multiple threads in the constructor, using the ExecutorService. And the doc here also support this kind of design. https://developer.android.com/training/multiple-threads/create-threadpool.html
 
yes the docs support but intentservice is created to use one job at a time, the service doc says so. it says to use multiple threading use startservice not intentservice. by the way it is your app do whatever you like.
 
Well, I will check specifically how to implement downloading files simultaneously with service in combination of ExcutorService. I'll appreciate it If you have such code for me to reference for.
A service is a background thread, if the user choose more files to download, how can I let the service do the download task? Should I create a queue to cache the download task and it's also observed by the service? Thanks!!!
 
However, because you handle each call to onStartCommand() yourself, you can perform multiple requests simultaneously. That's not what this example does, but if that's what you want, then you can create a new thread for each request and run then right away (instead of waiting for the previous request to finish).
or you can create blockingqueue as i mentioned in my answer then in your service create for example 5 threads that each of them can take messages from queue and parse them, this is the idea of volley library. if you want you can read the source code or you can search for other solution that uses one looper with multiple threads for handling.
 
Well, I am much interested in the library volley. Why should I reinvent a wheel after lots of failure and I can't meet the deadline. Does the library volley point to this http://developer.android.com/training/volley/index.html?
 
9:54 AM
but you can not download large file with volley so it is not downloadmanager it is for small files
 
As I know, if the file is not larger than 2GB and it's OK.
 
no my brother volley designed for downloading for example 2-3 MB i think it should not be used for downloading for example 50MB
 
only 50MB?
 
no i do not know but in presentation and in the document i think they said that it is not downloadmanager for example it is best suited for downloading listview or gridview and so on..
 
I just know that I shouldn't call startService each time, trying to perform a download task. It's just a background thread which is invoked only one time. So in my scenario, I should use a queue as you mention: a blocking queue
Have you ever implemented such a downloader? The download manager provided by Android is synchronous. It sucks.
 
9:59 AM
yes you can send a message to blocking queue and each thread if is idle look at the queue and take the message.
no i have not but
you can see how volley cachedispatcher and networkdispatcher work
and because of that i said look at volley source code
volley has 4 threads to download from internet
every request send to a blocking queue
 
and each thread take message from that
yes in that queue all of request is stored
then cachedispatcher take each one by one
if it is cached return result back
else send to networkdispatcher
in network dispatcher we have 4 threads
 
Well, can it interrupt the download progress?
 
yes it can
but you must spend some time to understand the library
it is intresting and is what you want
or search for other solution
 
Well, I didn't see the library use any Service or IntentService in combination
of BroacastReceiver
It's very traditional.
 
10:06 AM
yes library use thread only
you can use the IDEA
 
So it's a background thread?
 
and combine it with your service
 
Or run on the main thread.
 
create service and in that service use the IDEA of blockingqueue and multiple threads like networkdispatcher
each call onStartservice adds a message in to queue
and each threads read a message from that
and for refrence look at volley source code
or may be you can find looper with multipe threads
 
Wait, I call lots of startService(intent), and it gets error.
 
10:11 AM
i do not know is something like that can be implemented
 
I don't think that calling startService multiple times is a good idea.
 
i do not know what the error is ?
 
m... Well, should I allowed to call startService multiple times?
 
but in the docs it said if you want to implement simultaneous task call startservice
yes i think you should
 
Ya, but it lacks of example...
a helpful example...
 
10:14 AM
i have not any example but i think you can search and find
Good Luck Stallman
 
Ok, I will try to use the plugin directly, if it failed. I will turn to use multiple threads.
Thank you. If I found a good solution, I will update the question and choose your answer, hoping your help in the near future.
 

last day (14 days later) »