application
An entry point for the Compose application that blocks the calling thread until the application ends, and by default exits the process. See awaitApplication for more information.
Usually this entry point is used inside the main() function:
fun main() = application {
}After all windows are closed and all operations are completed, the application ends. Set exitProcessOnExit to false if you need to execute some code after the application block; otherwise that code won't be executed, as application exits the process.
This entry point is a blocking operation (it blocks the current thread until the application finishes) and can't be called on the UI thread: the composition it waits on runs its recomposer on that same thread, so calling from there would block the thread the wait depends on. To launch a new application from the UI thread (for example, from some event listener), use launchApplication instead.
The application can launch background tasks using androidx.compose.runtime.LaunchedEffect or create Window, Dialog, or org.jetbrains.compose.swing.components.Tray in a declarative Compose way:
fun main() = application {
var isSplashScreenShowing by remember { mutableStateOf(true) }
LaunchedEffect(Unit) {
delay(2000)
isSplashScreenShowing = false
}
if (isSplashScreenShowing) {
Window(::exitApplication, title = "Splash") {}
} else {
Window(::exitApplication, title = "App") {}
}
}When there are no active compositions left, this function ends. An active composition is one that has an active coroutine (for example, launched in androidx.compose.runtime.LaunchedEffect) or a child composition created inside Window, Dialog, or org.jetbrains.compose.swing.components.Tray.
Parameters
whether exitProcess(0) is called after the application is closed. The explicit exit ends the process immediately instead of waiting for background threads to wind down. If false, the execution of the function is unblocked after the application exits (when the last window is closed, and all androidx.compose.runtime.LaunchedEffects are complete).
the application's content, composed against an ApplicationScope.
See also
Throws
if called on the Event Dispatch Thread.