Android: Update / Refresh a running service

2019-08-01 12:25发布

问题:

I want to update my running service so I can for example, when the current day of the week is "Monday", it do a notification in a certain time that it's "Monday", and when it's "Tuesday" it do a notification that it's "Tuesday" and so on... The problem is, how to make my running service be refreshed or updated so that it can receive the updated day from the calender everyday? What I should use? TimerTask package (How)?, or make a Thread or what? and please if there is an example or a logic code for solving something like this it will be great if you posted it here... Thanks.

回答1:

Add a Broadcast receiver to your service, set an alarm using AlarmManager for that certain time for Monday, so that when the alarm goes off it starts the broadcast receiver of your service and inside the receiver you can set the alarm for the next day.

To add broadcast receiver to service see this