Skip to content

How to run the main function in KMP? #69

Discussion options

You must be logged in to vote

Hello, you cannot run an arbitrary main function in Android, but you have to follow the Activity Lifecycle. This is one simple example I set up, this is a super basic and useless example but it gives a starting point.

fun runClient() {
    CoroutineScope(Dispatchers.IO).launch {
        val client = MQTTClient(
            MQTTVersion.MQTT5,
            "test.mosquitto.org",
            8081,
            TLSClientSettings(serverCertificate = MOSQUITTO_CA_WS),
            keepAlive = 30,
            webSocket = "/mqtt"
        ) {
            println(it.payload?.toByteArray()?.decodeToString())
        }

        client.subscribe(
            listOf(
                Subscription(
         …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@prestondavid99
Comment options

Answer selected by prestondavid99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants