Frequency of polling on the server from the server

I want to get some data from the server every x minutes. If the information contains certain information, I would like to create a notification. I want this poll to occur even when the application is in the background or the phone is sleeping. I have some questions about polling in android.

  • What is the best way to do this? Should I use IntentService, AlarmManager, something else?

  • How often should I check the data? I would like to save it relatively often, say, every 10 minutes.

+6
source share
4 answers

I would prefer AlarmManager , because I try not to start constantly running services, if I really do not need it, but it really depends on how you use it.

If it were me, I would (based on a limited description): -

  • Configure AlarmManager to shoot in 10 minutes.
  • In response to an alarm, start a service that checks the data.
  • After the survey, he must set a new alarm in order to start it again in 10 minutes.
  • The service is shutting down.
+12
source

You want to use something like Cloud to Device Messaging (C2DM) (also called push notifications in the iPhone world)

A great tutorial can be found at http://blog.mediarain.com/2011/03/simple-google-android-c2dm-tutorial-push-notifications-for-android

+1
source

You can use Handler to listen on the server. For example, check Run code again and again

0
source

You can create a thread that will do this. In your startup method, you can create a loop that polls the server every 10 minutes.

-4
source

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


All Articles