Sobes.tech
Junior — Middle

How to launch a new Activity from a fragment?

sobes.tech AI

Answer from AI

To launch a new Activity from a fragment, you need to use an Intent object and the startActivity() method. It's important to obtain the context via requireContext() or getActivity(). Example:

val intent = Intent(requireContext(), NewActivity::class.java)
startActivity(intent)

If you need to get a result from the new Activity, you can use registerForActivityResult or startActivityForResult (deprecated method).

How to launch a new Activity from a fragment? — Android - sobes.tech