I like asynchstreams a lot but don't use it here. I only use it on local networks with up to 200 users or so. I do it like WhatsApp ;-)
I use this components:
- Firebase Messaging (to trigger that a new message is available)
- SQLite (to store the users and chats) lokal
- PHP & MySQL on my server (very powerful and you've got a layer between the app and the db to check logins, data, etc.)
- several Activities (like one for the chats list and one for the chat with a single user)
- services (to do all the db stuff and communication via OkHttpUtils with my server)
- ScrollViews (here you can add what you want like labels to display the messages)
PS: Instead of using own ScrollViews there are tons of ListViews here to use instead. Take a search.
Workflow
Device A -> User A sends message to User B -> OKHttpUtils Job -> My WebSite -> PHP -> DB -> Get User B's data -> Send FCM message to device B ->
-> get message from server, save it to the local db (and throw notification if app is in the background)
This is how WhatsApp does it.
Benefits
- no traffic on the server handling the messages (it is done by Google's FCM)
- no active connections all the time (this will kill your server). Imagine 1 bilion users are active...
- just a bit db traffic and some checks in php
- only when an app sends or fetches a message from the servers there is traffic on it
- most messages can be put to the FCM message as it can carry 4 KB (so no traffic on the server's db)
PS: Please edit the thread's title to a more specific one like "How to create an messenger app"