Question

I'm building an Android application that consumes a RESTful API. When I make a http request to the server I get a JSON response that I can then parse and display appropriately on the screen. So far so good.

Now as my application is going to have multiple users I'd like to refresh this information to all users when any of them changes it.

I know that you can accomplish something similar using AngularJS but I'm not sure you can use that on Android.

My only other idea is to make http requests from the mobile app every X period of time, say 30 seconds (but this is not very elegant and would consume lots of network resources).

Any ideas of how to solve this? Thanks!

PD: I used Laravel to build my REST API.

Était-ce utile?

La solution

Either you will use a background thread to check your server for changes every once in a while(basically polling from server), or you use push notifications (whenever something changes on your server side, server will push the data that changed to you). Preferably push should be the way you choose cause it is both user and battery friendly. Also eases your server load.

In android, push notifications implemented mostly by using GCM. You can read rest through here http://developer.android.com/google/gcm/index.html

For a local network, you can use MQTT. There is an excellent blog post about it here http://dalelane.co.uk/blog/?p=1599 .

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top