James Fazio
James Fazio

Reputation: 6450

Android Polling from a Server periodically

I want to pull some data from a server every x minutes. IF the info contains certain information I would like to create a notification. I want this polling to happen even when the app is in the background, or the phone is asleep. I have a few questions about polling in android.

Upvotes: 6

Views: 10678

Answers (4)

Luke Taylor
Luke Taylor

Reputation: 9599

You could create a thread that does this. In your run method you could create a loop that polls the server every 10 minutes.

Upvotes: -5

Kuffs
Kuffs

Reputation: 35651

I would favour an AlarmManager as I try not to run continuously running services unless I really need to but it does really depend on how you will be using it.

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

  1. Set up an AlarmManager to fire in say 10 minutes.
  2. In response to the alarm, start a service that polls the data.
  3. After polling it should set itself up with a new Alarm to fire again in another 10 minutes.
  4. The service shuts itself down.

Upvotes: 12

Brian
Brian

Reputation: 4984

You'll want to use something like Cloud to Device Messaging (C2DM) (aka 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

Upvotes: 1

Tuna Karakasoglu
Tuna Karakasoglu

Reputation: 1267

You could use Handler to listen the server. For example please check Run code over and over

Upvotes: 0

Related Questions