0

This may be duplicate question but am still having doubt am a beginner in android application i have a couple of doubts my primary doubt is:

  1. I have made one application which will communicate with server when network available it will work as it is. when network is not available data will save in sqlite and later when network is avail need to sync that data to server how can i achieve this.

  2. Whenever there is new update is made with server need to get notification how can i do this

  3. For this one which will be the best approach syncadapter or server or intent service with broadcast receiver which would be opptimized solution for the above requirement

These are all my doubts i would be very glad if someone helps me !!!

Yog
  • 137
  • 2
  • 14

2 Answers2

0

If you want an Android app to be notified when something happens on a server you control (without having the app to constantly poll the server to ask for changes), the usual solution is to use Google Cloud Messaging to allow the server to send a notification to the app to tell it to refresh data.

It is kind of complicated to implement, but is the best way to do what you want and is standard practice for mobile apps.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • then which would be best method syncadapter or intentservice with broadcast – Yog Feb 09 '16 at 07:25
  • It's not a matter of choosing from your list of options. Please look at what it takes to implement GCM in your app. It's more complicated than you think, but is far more useful. – Doug Stevenson Feb 09 '16 at 07:36
  • using broadcast can i push notification with intent service it is standard way right – Yog Feb 09 '16 at 07:40
  • Please consult the GCM documentation for the proper way to receive notifications from a server. It's too complicated to cover entirely here. If you have a problem integrating GCM, please post a new question with the relevant tags. – Doug Stevenson Feb 09 '16 at 07:49
0

If you need to know when the network becomes available, to reach your server for synchronization, implement connectivity change listener, as discussed in this question.

This does not allow to send messages from the server easily, but if the server messages are not of high urgency, maybe you can simply check for them periodically.

This would allow to use less Google specific infrastructure and change the cloud providers easier.

Community
  • 1
  • 1
Audrius Meškauskas
  • 20,936
  • 12
  • 75
  • 93