0

I'm try to make my Android App that send an HTTPRequest to a server repeatedly even when the App is not running (much like chat).The server will return a JSON file and if there is any update at the file, the app will send a notification to the user.
How can I do that?

Thnks.

Stefan Maimon
  • 233
  • 3
  • 12

2 Answers2

1

From you question i can only understand that you are polling from server. Repeated hit will drain your battery very fast and will exploit user bandwidth also. With this kind of mechanism there are changes that your app will be uninstalled very soon.

So, what i will suggest use push notification ,if there is any update let server tell you. There is no need for client to ask for it.

One more way but complicated both at server and client side is you can open your own TCP socket and can then you can share as much data in both direction.

I can suggest you to go with push-notification for easy implementation and do right thing.

Suhail Mehta
  • 5,514
  • 2
  • 23
  • 37
  • Hi @Suhail, thanks for the response. my response to the client depend on his current ip - therefor I must notify the server what is the device ip. You have any idea how to do that without exploit user bandwidth? – Stefan Maimon Feb 17 '15 at 14:51
  • you can create a event that will trigger when ever device connect to a network – Suhail Mehta Feb 17 '15 at 14:56
  • OK ! can you show me some code example of what you mean ? – Stefan Maimon Feb 17 '15 at 15:03
  • check this http://stackoverflow.com/questions/6179906/how-can-i-receive-a-notification-when-the-device-loses-network-connectivity and http://stackoverflow.com/questions/3125284/how-can-we-get-notified-if-the-phone-has-got-internet-access – Suhail Mehta Feb 17 '15 at 15:15
0

You have to use Service as explain here : http://developer.android.com/reference/android/app/Service.html

Only service could run in background when Activity are not visible.

LaurentY
  • 7,495
  • 3
  • 37
  • 55