androidlistenermessaginginstant

Creating an instant messaging app for Android


I'm trying to do an instant messaging app for Android, I have made the interface to send the messages to my database and it works fine. The problem is I dont have idea about how I can make a listener to receive the in coming messages from the database.

I was thinking to use a Timer to ask every 5 or 10 seconds and in case there are new messages for the client, download it. I tried it and if I'm using the app it works but when I'm use the same code to notify the client about new messages the timer doesn't work and the client never is notified.

Hope you can help me with some ideas. Thanks.


Solution

  • using a timer would abcolutly kill the phones battery at that interval. You need to look into using Google Cloud Messaging or XMPP to notify the device that a new message arrived