0% found this document useful (0 votes)
4 views1 page

Android Exit Confirmation Dialog Code

The document contains a Kotlin class for an Android activity named MainActivity, which prompts the user with an alert dialog when they attempt to exit the app. The layout file activity_main.xml defines a simple user interface with a button. The alert dialog confirms whether the user wants to exit the application, but the exit action is currently commented out in the code.

Uploaded by

sahilgolatkar0
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Android Exit Confirmation Dialog Code

The document contains a Kotlin class for an Android activity named MainActivity, which prompts the user with an alert dialog when they attempt to exit the app. The layout file activity_main.xml defines a simple user interface with a button. The alert dialog confirms whether the user wants to exit the application, but the exit action is currently commented out in the code.

Uploaded by

sahilgolatkar0
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

MainActivity.

kt :
package [Link].prac6

import [Link]
import [Link]
import [Link]
import [Link]
import [Link]

class MainActivity : AppCompatActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
setContentView([Link].activity_main)
}

override fun onBackPressed() {


val builder = [Link](this)
[Link]("are you sure you want to exit ?")
[Link]("Alert!")
[Link](false)
[Link]("Yes")
{
dialog, which -> [Link]()
}
val alertDialog = [Link]()
[Link]()

//[Link]()
}
}

activity_main.xml :

<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link] android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="click"
tools:layout_editor_absoluteX="160dp"
tools:layout_editor_absoluteY="323dp" />

</[Link]>

You might also like