What are the best practices for creating a chat application in Android

I am going to create an Android app. In fact, chat will be a feature of the application. I want to know what are the best practices regarding Android chats. Two options that I'm familiar with are C2MD and just a selective db server polling every few seconds.

Now I know that C2MD should be great and that’s it, but from my understanding it is not so reliable. I tried to implement it and it does not seem to work. In addition, if for some reason something happens at the end of the googles (for example, their servers are down - it’s unlikely, but it can happen), I can’t contact them and I’m in their time interval.

Now, if I do my job (a basic approach, when I send a message that the user creates and then periodically checks the server to see if any new messages have appeared), it seems that this is normal, except to have decent user experience, my survey of my server should have been as always 5 seconds or so, and this is going to chew on the battery like crazy. This is really my main drawback from using this approach.

So, I am wondering if there is a better way that I do not know. Please, any help, architecture structures, everything will be useful.

+7
source share
1 answer

You should look at using XMPP. You can search for StackOverflow for Android XMPP, and you will probably find yourself here where it is recommended to use some variant of Smack (XMPP client library).

Update for comments:

First, XMPP is a protocol, not a client or server. One of the advantages of using it is that the XMPP client and server implementations are widely available. The Wikipedia article addresses most of your questions.

Regarding your gtalk comment:

XMPP network architecture is similar to email; everyone can run their own XMPP server, and the central server does not exist.

Regarding the survey:

XMPP can use HTTP in two ways: polling [21] and binding. [22] The polling method, now obsolete, essentially means that messages stored in the server-side database are regularly uploaded (and published) by the XMPP client via HTTP "GET" and "POST" requests. With HTTP binding, the client uses longer HTTP connections to receive messages immediately after they are sent. This push notification model is more efficient than polling when many polls do not return new data.

It can also use WebSockets.

Regarding .NET integration (if you need it ... if you don't, you can just start your own XMPP server), you can just look for StackOverflow for XMPP and .NET, and you can get some questions / ideas around Integration .NET servers with XMPP servers, for example, with this question: Open .Net Jabber / XMPP server?

+8
source

All Articles