Mudasir Younas
Jul 24 · 4 min read
MyS3Chat — Complete Open Source Real Time Android Chat Application using Firebase
MyS3Chat — Complete Open Source Real Time Android Chat Application using Firebase

In this tutorial we will be developing real-time chat application using firebase, At the end of this tutorial, you will have a complete working android application ready to be published on playstore, exited? Let’s get started.



This tutorial assumes that you have basic knowledge of Java and Android SDK, you have built through small android applications and you are ready to apply your learning on some real projects.


· Android studio is installed and Android SDK is configured

· Android Physical or virtual device is ready for testing our application

· An account of firebase real-time database

What is firebase real-time database?

The Firebase Realtime Database is a cloud-hosted NoSQL database that lets you store and sync data between your users in realtime. We will be using this database to sync data between users and show notification whenever a new message arrives.

What is Retrofit:

Retrofit is an HTTP client for android, we will be using this library to parse firebase responses.

What is SQLite:

SQLite is a local database which we will use to store data already fetched from server to avoid sending request each time a user opens a chat activity.

Alright, so I will not be going to each code and explain what the code is doing rather explain some important classes and leave rest for you play with.

This will be our main activity where the user first lands, In this activity we will be first checking if a user is logged in and redirecting him to ActivityLogin if not logged in. After successfully logging in, the first thing we will be showing on our application’s main activity is chat history (if there is any), that’s what any user will be looking for.

At the very first login, we fetch data from firabase and store in local DB using SQLite, and at the later we do fetch chat history from end user’s local storage.

To avoid main thread freezing, each request to the network is made in a new task.

After successfully showing chat history user can click on any friends chat and we will send him to chat activity. If the user does not have any contacts he can goto search option, where he can search by name, email and send a connection request.
This class is responsible for listening to firebase and Show user a notification whenever there is any new activity, new message, new connection request, etc.
This is the class where we handle all local data storage for getting chat history, getting contact lists, deleting contacts, saving the new message to local storage, etc.
İn this class I have implemented retrofit API to get a response from firebase as a JSON string.

That’s it, clone the project from GitHub, build on your android studio and there you have complete working android application, as I promised.

This Project is not very complex, but it’s also not very easy to understand if you have just landed your feet on android World.

Please feel free to contact me for any problem or if you don’t understand any part or if you just want to say hello.

The Startup

Medium's largest active publication, followed by +492K people. Follow to join our community.

Mudasir Younas

Written by

Software Engineer

The Startup

Medium's largest active publication, followed by +492K people. Follow to join our community.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade