I am just learning to use Services, and am sort of stuck.
I have an IntentService
that I use to download a queue of files. I have an Activity
that has the ability to turn what files should be downloaded on and off. After a file is done downloading I update a boolean in my SharedPreferences
. I have two questions/problems:
The original Activity that started the Service will most likely be gone, but is very possible that a new instance of that Activity has been started. In that case I need send a message to that Activity to check the SharedPreferences and update it's UI accordingly. Therfore my question is: How can I send a message to an Activity that may or may not be running?
The Activity can be turing on and off what files should be downloaded while the Service is running. This creates a couple situations. If the Service is not running and the file gets turned on, then I want to start it with this file added to it's queue. If the Service is running and the file gets turned on, then I want to simply add the file to it's queue. If the Service is not running and a file gets turned off, I already have a method to delete it. However, if the Service is running and has not downloaded the file I want to remove it from it's queue or if it is currently downloading it, to stop downloading it. I am keeping what files should be downloaded in my SharedPreferences, so I guess all of these could be covered by sending a message to the Service to check the SharedPreferences. This leads to my second question: How can I get if a Service is running, and if it is, send it a message?