One to One Android Chat using Firebase
<p>I need some clarifications.</p>

<p>I'm using Firebase realtime database.</p>

<p>Now I've to implement a realtime chat between two android devices. I need also push notifications.</p>

<p>So, the solution based on <em>realtime database</em> is to drop because if the app isn't running, it will not handle the <em>onChildAdded</em> event.</p>

<p>I read on the documentation that I can achieve my aim, using the <em>upstream message</em> from the device to the server. </p>

<p>Now, it's written also that we need an app server.</p>

<p>I just want to be clarified the need of the app server (XMPP or HTTP), and which is the entire flow of message m1 sent from the device A, and the notification on the device B.</p>

<p>In my opinion the app server should act as a <em>man in the middle</em>, so:</p>

<blockquote>
  <p>A ---> XMPP SERVER ---> FCM</p>
  
  <p>FCM ---> XMPP SERVER ---> B</p>
</blockquote>

<p>Is this the flow? 
On the documentation I can't understand if I'm right or not.
If so, how do I send a message from the FCM back to the XMPP Server? 
The notification message is sent from FCM to the client o from XMPP Server?</p>

<p>Please someone clarify me.</p>

<p>Other solution thought by me:
Since I find really powerful firebase realtime database, I thought these solution to walk around the problem:</p>

<ol>
<li>Create an app server the is listening for <code>onChildAdded</code> and when it changes send a notification to client device. </li>
<li>Creating a background service on the client app listening to <code>onChildAdded</code> and create notification when necessary.</li>
</ol>

<p>Even all, I don't like these solutions. 
Just want to understand the standard and correct way to achieve my aim.</p>