You won't get around AlarmManager
. The only other client-side way would be to use a permanently running Service
, but that is even more effort and less efficient.
Polling a database with long interval times, which is the best and most efficient way?
-
14-10-2022 - |
Question
How should I do this? I have been reading the posts but I don't see a clear answer to tell the truth.
I have been looking up the AlarmManager
but it looked too complicated for something as simple as I want. I searched through the Timer
class now, but I think you can't make it work when the application is closed. So which way should I choose? Which is the best way to check the server from time to time even if the app. is closed?
Thanks in advance.
Solution
OTHER TIPS
As per the question i will favor the AlarmManager
as do not run the continuous services, for this purpose you can follow given steps
1 Set up an AlarmManager to fire in say 5 minutes, you can use yours timings 5 minutes is just arbitrary.
2 In the response of the alarm , you can start a service that will be able to poll the data.
3 After polling it can set itself up with a new Alarm to fire again in another 5 minutes.
4 The service shuts down finally.