Let's say my application receives a push notification from a server that carries an item ID. After receiving the push notification item's details have to be fetched from the server (using retrofit) and after that an Android notification is displayed. This is pretty straightforward when a phone is not idle.
But what happens when, e.g. I lock the phone and keep it that way? After a time the phone goes to sleep. Push notification should be received. But what bugs my mind is the retrofit call. Will the application stay awake till I finish - dispose - the retrofit call or it can be "killed" while handling it? Does it have to do something with so called WakeLock? Or is it a bad way to use retrofit in a first place? I couldn't find any good article or example that will help me understand.
My solution: I managed it using Evernote's Android Job
library (there is also an option with FirebaseJob
- mentioned in code samples on FCM documentation page). With Android Job
I schedule call after I receive the push notification. Had to use blocking RX calls so the result wouldn't overtake retrofit response: https://github.com/evernote/android-job/wiki/FAQ#how-can-i-run-async-operations-in-a-job