Let’s say I have an Android
DialogFragment
that uses a
ViewModel
with
viewModelScope
support. In the UI, the user fills in a bunch of data and the click a
Submit button which closes the dialog and does a
HTTP POST
of the data. Let’s say I use
Retrofit2
with
suspend
support.
I should clearly not use
viewModelScope.launch
to do the
HTTP POST
because it will be cancelled when the UI is closed.
Naive as am, I think it would be fine to use
GlobalScope.launch
in this case to do the
HTTP POST
, since I under no circumstances want that
HTTP POST
to be cancelled.
Would this be bad style? If yes, what scope should I use instead? Some
CoroutineScope
field in my Android
Application
class perhaps? Let’s ignore edge cases like network failure for now.