Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To exit an app from a fragment using Kotlin, you can use the following code:

activity?.finish()

This code will call the finish() method on the current activity, which will close the app and take the user back to the home screen.

Alternatively, if you want to close only the current fragment and return to the previous fragment, you can use the following code:

activity?.supportFragmentManager?.popBackStack()

This code will pop the current fragment from the back stack and return to the previous fragment, or close the activity if there are no fragments left in the back stack.