I am trying to build a chat app using XMPP + PHP home made API + Local Android database. I wanted to use XMPP running in the background (as a service or a background Job) to tell my app to fetch data from the API if a new message arrived. Then store it in the local database, and update my messages box with the updated content.
The XMPP client is working fine in foreground (Lolipop and OREO) But when I close the app (slide to the side, not hard kill), it still works for maybe 5 minutes then it idle and 2 min later back up again for 5 min and so on. (On Lolipop). And it immidiately stops on OREO.
I know that OREO needs Job Scheduler to manage my background task. But why does my service stops after 5 minutes on Lolipop ?
I tried to override the onDestroy method of my Service:
https://stackoverflow.com/a/43936309/10651475
but it doesn't changes anything.
And how should I implement my Background Job on OREO ? The job is running once, and can be restarted periodically but I want to keep it running in order to receive new messages immidiately even if I have not been using my phone for 2 hours.
WhatsApp, Facebook Messanger, Snapchat and Instagram are doing all this perfectly on both versions (Lolipop & OREO). But how they do this ???
I forgot to mention that all those apps don't have a pending notification displayed.
I read a lot a discussions about this topic. It seams that they use Push Notifications, GoogleCloudMessaging etc. But I feel like I’m forced to use GCM, Firebase and all this Ecosystem.
Should I understand that Google is locking Android years after years ?
How does whatsapp Keeps its eJabberd/XMPP server connected when the app is Closed?
I read those articles and much more, but I didn’t find my answer there...
If you have an idea, it would help me a lot.
Thank you :)