Android Jetpack Compose - Close Application By Button Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report When we are implementing an AlertDialog within the android application for asking for permissions within the android application. In that case, we provide 2 options either to grant permissions or close the application. In this article, we will take a look at How to quit an android application programmatically using Jetpack Compose.Step by Step ImplementationStep 1: Create a New Project in Android StudioTo create a new project in the Android Studio, please refer to How to Create a new Project in Android Studio with Jetpack Compose.Step 3: Working with the MainActivity.kt fileGo to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.MainActivity.kt: Kotlin package com.geeksforgeeks.demo import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.layout.* import androidx.compose.material3.* import androidx.compose.runtime.Composable import androidx.compose.ui.* import androidx.compose.ui.graphics.Color import com.geeksforgeeks.demo.ui.theme.DemoTheme import kotlin.system.exitProcess class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { DemoTheme(dynamicColor = false, darkTheme = false) { Surface(color = Color.White) { CloseAppWithAButton() } } } } } @Composable fun CloseAppWithAButton() { Box( modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center ) { Button( onClick = { // this closes the main activity MainActivity().finish() // this closes the application exitProcess(0) } ) { Text(text = "Close App") } } } Output: Create Quiz Comment C chaitanyamunje Follow 0 Improve C chaitanyamunje Follow 0 Improve Article Tags : Kotlin Android-Jetpack Explore OverviewIntroduction to Kotlin4 min readKotlin Environment setup for Command Line2 min readKotlin Environment setup with Intellij IDEA2 min readHello World program in Kotlin2 min readBasicsKotlin Data Types3 min readKotlin Variables2 min readKotlin Operators4 min readKotlin Standard Input/Output4 min readKotlin Type Conversion2 min readKotlin Expression, Statement and Block4 min readControl FlowKotlin if-else expression4 min readKotlin while loop2 min readKotlin do-while loop2 min readKotlin for loop4 min readKotlin when expression6 min readKotlin Unlabelled break4 min readKotlin labelled continue4 min readArray & StringKotlin Array6 min readKotlin String4 min readFunctionsKotlin functions7 min readKotlin Default and Named argument7 min readKotlin Recursion3 min readKotlin Tail Recursion2 min readKotlin Lambdas Expressions and Anonymous Functions6 min readKotlin Inline Functions5 min readKotlin infix function notation5 min readKotlin Higher-Order Functions6 min readCollectionsKotlin Collections6 min readKotlin list : Arraylist6 min readKotlin list : listOf()7 min readKotlin Set : setOf()4 min readKotlin hashSetOf()4 min readKotlin Map : mapOf()5 min readKotlin Hashmap7 min readOOPs ConceptKotlin Class and Objects4 min readKotlin Nested class and Inner class3 min readKotlin Setters and Getters4 min readKotlin Class Properties and Custom Accessors3 min readKotlin Constructor6 min readKotlin Visibility Modifiers6 min readKotlin Inheritance10 min readKotlin Interfaces7 min readKotlin Data Classes3 min readKotlin Sealed Classes4 min readKotlin Abstract class5 min readEnum Classes in Kotlin4 min readKotlin extension function4 min readKotlin generics6 min readException HandlingKotlin Exception Handling - try, catch, throw and finally5 min readKotlin Nested try block and multiple catch block3 min readNull SafetyKotlin Null Safety7 min readKotlin Type Checking and Smart Casting3 min readKotlin Explicit Type Casting3 min readRegex & RangesKotlin Regular Expression4 min readKotlin Ranges3 min read Like