Android Jetpack Compose - Close Application By Button Last Updated : 07 Mar, 2025 Summarize Comments Improve Suggest changes Share 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: Comment More infoAdvertise with us Next Article Button in Android using Jetpack Compose C chaitanyamunje Follow Improve Article Tags : Kotlin Android-Jetpack Similar Reads Chat Application in Android Jetpack Compose Chat Application are common application across Android world leading tech companies are directly or indirectly involved in such kind of Application. In this article, we will Create a Chat Application Using Android Jetpack Compose and integrate it with Firebase to enable real-time Message exchange.Pr 8 min read Change Button Size in Android Jetpack Compose In Android, Button is a very common UI element that is used to call a function or perform a task when clicked by the user. A Button by default occupies specific space depending upon the text that it displays. If the Button text is longer or has a larger font size, the Button width, and height increa 3 min read Button in Android using Jetpack Compose Jetpack Compose is a new toolkit provided by Google. This is useful for designing beautiful UI designs. A Button is a UI component in Android which is used to navigate between different screens. With the help of a button, the user can interact with your app and perform multiple actions inside your a 3 min read Send Email in an Android Application using Jetpack Compose Many times while building an android application. We have to send a mail to any specific address from our android application. Inside this mail, we have to define the email address, subject, and body to be sent over Gmail or any other mail application. In this article, we will be building a simple a 7 min read Basics of Jetpack Compose in Android Jetpack Compose is a modern UI toolkit that is designed to simplify UI development in Android. It consists of a reactive programming model with conciseness and ease of Kotlin programming language. It is fully declarative so that you can describe your UI by calling some series of functions that will 5 min read How to Build a Photo Viewing Application in Android using Jetpack Compose? Gallery App is one of the most used Applications which comes pre-installed on many Android devices and there are several different applications that are present in Google Play to view the media files present in a device. In this article, we will be building a simple Gallery Application for Android u 10 min read Like