Hi guys ,
I want to do some data syncing like calling a api and then inserting the data into room database. What will be the best approach for this?
1. GlobalScope
2. Work manager
3. Service
not kotlin but kotlin colored 6
Debdut Saha
08/28/2023, 6:03 PM
If there are other options please let me know.
c
Chrimaeon
08/28/2023, 6:29 PM
Wrong workspace. Over here we talk about the Kotlin programming language and all related topics. You question is pure android and should be asked on a different platform.
a
Alex
08/29/2023, 7:47 AM
To answer your question anyways:
It depends on your usecase, if the data does not need to be up to date to the minute you should use workmanager so the system can schedule the update to when its convenient.
A service would only be required if you need to update the data in the background and at a very specified time (not for example once a day, no matter when).
GlobalScope should only rarely be the answer, you should rather use MainScope but that would probably wrong too, since even the MainScope will only live as long as the app is running.