Alexander Suraphel

    Alexander Suraphel

    10 months ago
    What do you recommend for background work instead of WorkManager to do background work?
    Benoît

    Benoît

    10 months ago
    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
    Alexander Suraphel

    Alexander Suraphel

    10 months ago
    @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…
    Benoît

    Benoît

    10 months ago
    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
    Alexander Suraphel

    Alexander Suraphel

    10 months ago
    Thanks a lot @Benoît. This is exactly why I love KM. It lets you write platform specific code when it makes sense
    Benoît

    Benoît

    10 months ago
    That's what we all love about it 😄 You only share what makes sense
    @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
    Alexander Suraphel

    Alexander Suraphel

    10 months ago
    @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!