Hello team, I’m pretty much new in KMM and need so...
# multiplatform
c
Hello team, I’m pretty much new in KMM and need some guidance 🙂 Currently I have an Android app where it triggers the
WorkerManager
periodically every 30 minutes in the background to execute some tasks. One of the task is downloading the image from remote server and then store the image file in the local storage. My Questions are 1. How to implement the
WorkerManager
that will be triggered every 30 minutes in KMM ? (of course I hope it runs on Android and IOS) 2. How to store the image file in the local storage ? To make things even more confusing to me, currently in Android we have that thing called
Scoped Storage
. I’m not sure if IOS has this kind of concept as well. How to get around with this problem ?
m
AFAIK WorkerManager is an Android only concept and not part of Compose. 1. I solved that via a loop in a coroutine and a delay statement. 2. You can use Okio to access the local filesystem on Android and iOS but you will have to figure out what the correct storage location on each platform is. I have my own native solution for that because I am not aware of any multi-platform library for that.
c
Thank you very much for your answer 🙏 🙂 @Michael Paus I still have another question regarding the
WorkerManager
. In Android, if we use
WorkerManager
we will have this behavior where the worker is still running in the background even when the app is destroyed. I don't think we will get the same behavior if we use loop & delay statement in coroutine right ?
m
I am neither an Android nor a Coroutine expert and I also have never used the WorkerManager but I think this would depend on the coroutine scope you are using. You could run an experiment by just using GlobalScope.
c
Got it, thank you sir :)
k
Agreed, not sure about
WorkManager
but I would image you could create a service that calls shared code, or even just use your current
WorkManager
to call the shared code function. If you need some guidance on getting started, you can view the
KaMPKit
sample project https://github.com/touchlab/KaMPKit. It goes over how to download data online and storing it to a database using
SQLDelight
. Not sure if you’d want a database for images but it could at least be a starting point.
d
Touchlab…. 👉 🐕‍🦺