I want to trigger an api call in my FirebaseMessagingService but I am facing problems when the app is closed.
I have tried injecting a repository directly in the service and perform an api call in onMessageReceived() using a coroutine, but the coroutine gets killed instantly (right after notification gets displayed on my device) and no call is performed.
Then I have replaced the coroutine with a OneTimeWorker which contains the repository this time. Everything well, the worker works as expected, even if I very rapidly close the app after the notification arrives.
However, noting works if the app is closed, the worker doesn't work anymore. So the app is closed, I get the notification in the tray but the call is not performed. I check with Postman if the call has been performed to test so I know for sure the worker and the call wasn't successful.
Any ideas on how to solve this issue and make it work while the app is closed?