Setting the VS Timer Using the Alarm Manager in the Android Service

I need to regularly receive news / events updates from the server, like every 20 minutes in my Android app. The combination of AFAIK Intent Service and Broadcast Receiver will be better than using the service. Since I am not going to communicate with a working service. To receive events at regular intervals, I know 2 options

1) Using the Timer Task ScheduleAtFixedRate, I am going to launch an IntentService, which will retrieve events once and broadcast if there are any updates and destroy ourselves. After the specified IntentService interval, TimerTask will start again

2) Just start the Intent Service at the beginning of the application and inside the Intent Service onHandleIntent. Launch TimerTask ScheduleAtFixedRate. If this is the preferred way, how and when will I cancel the timer task and when will the intent service be destroyed.

or I need to use Alarm Manager. Note. I need these updates if I use the application, I also need updates every 20-30 minutes, not every 1 or 3 minutes.

Any body, please suggest me, thanks in Advance.

+6
source share
1 answer

Go to AlarmManager. I already tried TimerTask, in some devices it does not work properly and will be killed after a while.

+7
source

Source: https://habr.com/ru/post/904744/


All Articles