In Android I have an application with different activities and a service. The activities are for direct user interaction, in which the user can change data, update data, entry data, whatever.
The application also has a (background) service running, using the data the user has entered (stock data). The service regulary checks the stock prices (e.g. every 12 hours) and gives the user a notification, if some conditions match.
However, as an user I want to be able to change settings of this service. I start the application, and can enter an update interval in one of the application's activity which is stored in a SharedPreference
. I am able to change the value, for example, to have the service check the stock data every 3 hours instead.
Do I then have to 'restart' the service? As I understand 'services' in an operating system, the service runs until stopped by some event. But if the service is not stopped, the service does not 'notice' that the update interval has changed! So, in my activity from my main application I need some way to 'restart' the service, so it checks the stock prices in 3 hours, and not in 12 hours!
Any idea how to accomplish this? A google search did not really help. Maybe I looked for the wrong keywords...?