Ask Your Question
4

In Android, how can an app be exited from a fragment using Kotlin?

asked 2022-11-30 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-01-17 05:00:00 +0000

nofretete gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-11-30 11:00:00 +0000

Seen: 10 times

Last updated: Jan 17 '22