I have a Service which its responsibility is to download files from Internet. My Service can download multiple files at the same time.I should be able to send requests to my Service from different classes, e.g., from Activities, Fragments or NotificationManager.
What is the best way to send download requests to the Service?. should I send the data via Intent or it is better to access to the reference of the Service and call one of it's public functions? Which one is better? Thanks.
I'd say it depends. If all you need to do is give the service some task to perform and you don't want any response from it, then you should just send the info via an intent and forget about it.
If you need to communicate with the service about the download such as progress, download status, and other kinds of stuff like that, you should probably bind to the service (if you're using an activity).
If you're not using an activity and you need to communicate with the service, there's a number of ways you could implement communication. You could use an event interface where the service can send events to whoever cares to listen about its download progress, queues and other things like that. The other party can also send events to the service which might prompt the service to respond with another event or perform some task. This way, you don't keep a reference to a service that can be killed anytime by Android. You'll just know that if you send an event to the service and you don't get a response back, then the service is dead (or it just doesn't want to respond).