How can I open a new Activity inside of a fragment when using a button?
I tried this
override fun onViewCreated(view: View, savedInstanceState: Bundle?
If you only use activity
returns just an Activity instance. This can be any activity that embeds your fragment so in some cases you can get FragmentActivity instead your parent activity. Use this to make use you are getting the correct one:
(activity as YourParentActivity?)?.let{
val intent = Intent (it, Main::class.java)
it.startActivity(intent)
}