I have a question regarding Cloudant.
Basically, we have an application which aims to coordinate a common time for people to meet up when they are free, which will be indicated by their "voting" on the app.
So here's the thing, we've figured out how to start Pull Replication from Cloudant, and any changes will then be updated in our database. Let's call this method onReceiveUpdate().
Our current approach is to encase this onReceiveUpdate() method in an infinite loop, within a service, as so:
@Override
protected Void doInBackground(Void... params) {
while (true) {
onReceiveUpdate();
}
return null;
}
Obviously, this is a bad design, which I realized when my phone started overheating. I decided to read more, and came across Cloudant's Eventbus/Event
However, I wasn't sure if this would allow me to be notified when there are changes made to Cloundant's database. So I went and research more and found Google Cloud Messaging.
My approach now is:
- Set up documents for each users.
- Any changes relevant to the user, will result in their corresponding documents being modified.
- Cloudant will then notify Google Cloud Messaging of the fact that a document has been modified. And hence it should send a notification to Google Cloud Messaging ,tagged with the relevant registration ID.
- Google Cloud Messaging should then inform the relevant user (through the registration ID) of updates, which will then finally result in the actual user calling
onReceiveUpdate().
Question: How do I implement step 3? That is to say, how do I ensure that Cloudant will send a "send properly formatted requests to the GCM connection server" (from here), if and when there are changes made? I read through their documentation, but I didn't catch anything yet.
Otherwise, is there any other less battery-intensive alternative to pull replication from Cloudant?