If you send a message it will show up in your database, you can see it in in the Firebase console under Realtime Database.

App for reading the messages

A simple App reads the messages from the firebase database and show them as a list.

You can register the App in setting in the Firebase console. Follow the instruction for what to add to the gradle build files.

You can read more about how to setup and handel MVVM and Injection in other blog posts.

The message is read in the MessageModel model from the firebase database and update a map containing the message.

database.addValueEventListener(object:ValueEventListener{overridefunonDataChange(snapshot:DataSnapshot){valrecordMap=mutableMapOf<String,MessageRecord>()// Read the data from the snapshot
snapshot.children.forEach{valkey=it.keyvaltimestamp=it.child("timestamp").getValue(Long::class.java)?:0valemail=it.child("email").getValue(String::class.java)?:""valsubject=it.child("subject").getValue(String::class.java)?:""valmessage=it.child("message").getValue(String::class.java)?:""key?.let{messageId->valrecord=MessageRecord(messageId,timestamp,email,subject,message)recordMap[messageId]=record}}// Update the message map.
messageMap.value=recordMap}overridefunonCancelled(error:DatabaseError){// Show a toast if something went wrong.
Toast.makeText(application,error.message,Toast.LENGTH_LONG).show()}})

The map is then transformed to an list and then get sorted by its timestamp.