If you want keep your async operations while you Android device is rotating you should launch your coroutines from the scope of your ViewModel. Unlike activities, your ViewModels keep working while device is rotating, so all the coroutines in the context of ViewModel keep running. You ViewModel should have some LiveData for “operation is running” state that you can reset when you receive response or error from your backend.

Written by

Project Lead for the Kotlin Programming Language @JetBrains

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store