I found two possible approaches to deliver notifications after some changes in the Firebase real time database (for example in a chat application):
It is possible to use Cloud Functions for Firebase as explained in this blog post.
I have also found here another simpler approach using just an android service that listens for changes in the database.
I would like to know what are the pros and the cons of the two approaches before trying to implement one of them and since the second one seems much simpler than the first one.