https://kotlinlang.org logo
#coroutines
Title
# coroutines
c

clhols

06/04/2020, 3:58 PM
Have an Android app that launches the following coroutine when the app goes in the background (all activities are stopped):
Copy code
sessionTimeOutJob = GlobalScope.launch {
  delay(5.minutes)
  activity.finishAffinity()
}
So after 5 minutes the coroutine should resume and call finishAffinity(). But it doesn't happen on release builds. Only on debug builds. On release builds it first resumes when the app is selected in the Recents menu. Long past the 5 minute mark. Is it somehow the app lifecycle that prevents the coroutine from resuming?
I guess this is more an Android question than a coroutine question. The Android emulator actually resumes the coroutine, but the OnePlus 7 does not. My guess is that this is an Android optimization to prevent background work.
a

Adam Powell

06/04/2020, 6:49 PM
Probably. The system may choose to
kill -9
your process any time it likes, that's probably what's happening here shortly after your activities leave the foreground.
6 Views