Simon Lin
03/29/2021, 1:59 AMviewModelScope
, it would be clear when view destroy.
Using Globalscope
is a good idea?Ernestas
03/29/2021, 5:28 AMSimon Lin
03/29/2021, 5:30 AMSimon Lin
03/29/2021, 5:33 AMIqbal Ahmed
03/29/2021, 5:43 AMWorkManager
Simon Lin
03/29/2021, 5:45 AMWorkManager
is also suitable for immediately work?
In this case we need to call api to tell server side that our user leave the page (for example: purchase page)Simon Lin
03/29/2021, 5:53 AMSimon Lin
03/29/2021, 5:57 AMIqbal Ahmed
03/29/2021, 6:03 AMWorkManager
, you may be execute OneTimeWorker for immediate operation. or else in viewmodel
you can call API and in your Repo you can change CoroutineContext to IO
, I am not sure but you can give a tryErnestas
03/29/2021, 6:07 AMErnestas
03/29/2021, 6:13 AMTower Guidev2
03/29/2021, 7:21 AMSimon Lin
03/29/2021, 7:27 AMIqbal Ahmed
03/29/2021, 7:33 AM(<http://Dispatchers.IO|Dispatchers.IO>)
in Repository?Simon Lin
03/29/2021, 7:36 AMTower Guidev2
03/29/2021, 8:31 AMHow do I call a network api when the fragment destroy?
The question is: I don't think the work is "background work".
Our app is always foreground in the case.You are calling a network API, thats "_*background*_" work, e.g NOT executed on MAIN thread