What do you recommend for background work instead ...
# multiplatform
a
What do you recommend for background work instead of WorkManager to do background work?
b
Each platform is different for this so what I usually do is write the function that does the work in a platform agnostic way and implement the triggering of the work independently on each platforms
👍 1
a
@Benoît i just hoped there’d be a kotlin/native way of doing it as I am also implementing a desktop app. Any idea how to do it for desktop? JVM based would work too…
b
On Android, the reason you'd use a WorkManager is to make sure a piece of code runs, even if your process gets killed. Your process can't get killed on desktop like it could on Android Another reason to use WorkManager is to trigger work when certain conditions are met: high battery level, on WiFi, etc. This does not apply to desktop either. So for desktop, I would just call
GlobalScope.launch{}
and on Android I'd use WorkManager
🙏 1
a
Thanks a lot @Benoît. This is exactly why I love KM. It lets you write platform specific code when it makes sense
b
That's what we all love about it 😄 You only share what makes sense
💯 1
@Alexander Suraphel Just one last note actually, on Android your work is guaranteed to be executed by Google basically, however if you do a
GlobalScope.launch
on desktop and your process gets killed somehow, for example if a fatal crash happens somewhere else in your code which causes the death of the process, then your work would be lost. On Android the WorkManager would restart your work a bit later. So you might wanna implement a custom solution to handle that edge case on desktop
a
@Benoît that’s i had used Quartz for spring project a few years ago. I’ll look into it or if a better project exists. Thanks for the heads up!
👍 1