2

My Android app currently uses Volley for HTTP communication with my web service built with django rest framework. My backend consists of a MySQL database and python.

The app will consist of multiple users updating the same page. I would like this page to update close to real time. When there is an update to the database (via the web service) I would like to push those updates to all connected clients. I would prefer to push the data to the clients instead of polling the server.

What is the recommended approach to syncing a database to an Android UI?

Here are some of the options I have come across:

Android Sync Adapter

Firebase Cloud Messaging (If I go this route will I need to migrate my database?)

PubNub

Is there a way to accomplish this with Volley?

Matt
  • 1,017
  • 2
  • 11
  • 27
  • There are other options, for example MQTT (see Eclipse Paho for a Android client library) – mjn42 Aug 08 '16 at 14:28
  • So from my understanding of Volley, it is a req/resp library for android and has nothing to do with pulling data. I don't think you can accomplish what you want to do with Volley. Unless you want to be polling but based on your question above, I doubt you would want to do that. – The Code Pimp Aug 08 '16 at 14:55
  • possible duplicate of http://stackoverflow.com/questions/1378671/push-notifications-in-android-platform and http://stackoverflow.com/questions/1243066/does-android-support-near-real-time-push-notification/ – k3b Aug 08 '16 at 16:03
  • In your question you mention connected devices, if you mean that you are only concerned about devices that are currently open then Firebase Realtime Database can do the trick. If you store your data there any changes are automatically synced to all connected clients. Clients that are not connected will be updated as they come online. – Arthur Thompson Aug 10 '16 at 18:09

1 Answers1

1

I would suggest you use PubNub of the realtime data management and then use either broadcast receivers, EventBus or Otto to fire events that you listen to locally. Let me explain it bit more.

In your database, when there is a successful CRUD operation, you can publish this to the PubNub server. This will in turn fire off to your clients that are subscribers. Then in your application, you can have a android service that is running and it will then listen and process the pub nub events that are being received. At that point, you can then fire local events within your application using EventBus or Otto and have your views react to those events. Now the reason I am suggesting separating out the event management is so that if you change realtime data providers, it will require very little code change in your application since it it encapsulated in the android service and not throughout your application.

The Code Pimp
  • 2,196
  • 1
  • 17
  • 16
  • The question is about updating the database on a remote web service and inform other android clients about the changes. Are you shure that PubNub can run on a webserver and send a broadcast to the android-devices? – k3b Aug 08 '16 at 15:24
  • As far as I know, yes. I just went to the PubNub knowledge base and saw this: https://www.pubnub.com/knowledge-base/discussion/296/can-i-publish-a-message-via-a-database-trigger .Unless I totally misunderstood the question I think it is fairly straightforward based on this example. – The Code Pimp Aug 08 '16 at 15:31
  • @The Code Pimp - yes, just pay much attention to the *NOTE* at the top of that KB article. And you can publish the db updates with a FCM (formerly GCM) push payload so that the device gets the update when the app is in background or not running. – Craig Conover Aug 08 '16 at 16:22