Synchronize Android client and REST server

时光怂恿深爱的人放手 提交于 2019-11-29 10:55:53
rafb3

One simple architecture is to always update things in the server first, sending posted comments to the server right away and from there pushing a notification through GCM to users that should request the updated comments list. The flow would look like:

  • When the app is open send GCM registration id to your push notification server (say uniqush-push, or your own server using a gem to handle the GCM logic), this way you can use it to send push notifications to the user telling the app to update the comments from the server
  • Build your initial cache as you want it
  • Whenever a user posts a comment, send it to the server and make the server respond with the data for the created comment, so the app can use that and already cache it if it wants, using the returned id and whatever else
  • On the server, when a comment is posted, loop through all the concerned users and using the GCM registration id send it a push notification, it could be as simple as having just "update_comments": "1"
  • On the app when the push notification is tapped by the user, update the comments cache with a request to the server
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!