Android Question Question about making an instant message app

Alphaw

Member
Licensed User
Longtime User
Hi everyone,

I am going to make a small IM application, and I would like to know weather the concept is work or not:

1. A server with mysql, the table contain 2 columns, User and Content.
2. php file, 2 command inside which one for posting message content and other is getting the content of database.
3. In b4a app, a button which doing posting function with the edittext content by manual (just press the button and post content to mysql database).
4. Automatically doing the getting function to receive the content of database and show in the app (i.e. just clear and list content at listview every 5s or 10s).

My question is:
1. Does the concept work, or is it efficiency especially in point 4, since keep doing the getting function every 5s or 10s may waste the electricity of the phone a lot.
2. How can I achieve the auto-running function for send a command to get content?
3. Lastly, is it any other better way to do so, like doing Synchronization with mysql database when the there is new content entry in the database. Just like the whatsapp, we can get updater messages when we receive new message.

I am looking for any help. Thank you.
 

Roycefer

Well-Known Member
Licensed User
Longtime User
Upvote 0

Alphaw

Member
Licensed User
Longtime User
Have you looked at implementing a B4J server with WebSockets? i think this would be a more reliable solution and provide for better battery usage than 5 or 10 second interval polling.

Erel has provided a tutorial on B4J WebSockets that uses a chat room as an example: http://b4x.com/android/forum/threads/webapp-chatroom-threads-sessions-and-server-events.39969/ . I think you should read this and try it out.

Thank you Roycefer, let me try first although I am not familiar to B4J yet.
Anyway, thank you for your help.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Take a look at my tutorials (see signature).

I use XMAPP on my Notebook which Comes with PHP & MySql (for a test Environment). if you want to go online, get a cheap hoster which offer a website with php & MySql like I do. To get new Messages frequently, you could use a timer (simple) or better a Service (search the forum for it). There are "push-Frameworks" available (more complex), too.

The battery comsumption should be ok as long as you don't get messages every 1/10 seconds.
 
Upvote 0
Top