How to close activity for iOS app in Kotlin Multiplatform

332 Views Asked by At

In my Kotlin Multiplatform Android/iOS app, I have a dialogue popping up when the user starts the app, asking to confirm acceptance of the conditions of use. If he declines, then the activity should close/minimise.

I use an expect/actual function construct, with

expect fun closeapp()

in the commonMain module.

In the Android app, I use:

actual fun closeapp()
{
    System.exit(-1)
}

to implement closing of the activity. But I don't know how to achieve the equivalent in iosMain. Any thoughts?

1

There are 1 best solutions below

1
GURPREET SINGH On

Using System.exit(-1) in the actual implementation for closing the app on Android is a valid approach. It forcefully terminates the application process. However, note that using System.exit() in Android is generally not recommended unless it's a critical situation.

Here's your updated implementation:

// Example code to finish the activity on Android
android.app.Activity.finish()

// Example code to exit the app (not recommended in all situations)
System.exit(-1)