https://kotlinlang.org logo
j

John O'Reilly

10/09/2021, 6:02 PM
Are people using any particular approach for triggering the execution of shared code when application starts up (other than explicitly invoking from say Android and iOS app layer code at the appropriate time)?
b

Big Chungus

10/09/2021, 6:37 PM
Ktor has some funky mpp "service loader" implementation internally that executes arbitrary code at startup
j

John O'Reilly

10/09/2021, 6:42 PM
Yeah, I think at least one option is something like this where
init
block is used....and probably fine in many cases....feels though that something more structured is needed in more complex cases but maybe reality in that case is that it has be something that's explicitly triggered from app layer.
b

Big Chungus

10/09/2021, 6:45 PM
I'm still dreaming for official mpp "service loader" api. Clearly it's possible, just needs to be standardised
p

pererikbergman

10/10/2021, 3:57 AM
@John O'Reilly I am curious about the use case.
j

John O'Reilly

10/10/2021, 7:35 AM
One example might be some data you want to retrieve when app starts up
r

Rick Clephas

10/10/2021, 9:06 AM
Not sure about iOS but for Android you could use a ContentProvider in the shared module.
m

matej

10/11/2021, 9:40 AM
@Rick Clephas, @John O'Reilly on Android you can register a startup initializer in the Manifest and execute lbrary code on startup without relying on app code to call you.
🙌🏻 1
🙌 1
j

John O'Reilly

10/11/2021, 9:41 AM
Seems like there's a few approaches all right that can be used for Android....anybody come across anything similar for iOS (and potentially other platforms)?
Maybe reality is that something in app layer is going to be needed to trigger this.....
r

Rick Clephas

10/11/2021, 9:46 AM
Yeah in the end the app needs to trigger something one way or another. ContentProviders in Android can automate this but I am not aware of such an feature in iOS…
2 Views