0

There is an error in intent parameters and could not figure out how to solve this issue.

 companion object {
        fun start(context: BookingFragment) {
            context.startActivity(Intent(context, BookingFragment::class.java))
        }

//Error:

  None of the following functions can be called with the arguments supplied: 
    public constructor Intent(p0: Context!, p1: Class<*>!) defined in android.content.Intent
    public constructor Intent(p0: String!, p1: Uri!) defined in android.content.Intent
Hubby Tiwari
  • 313
  • 6
  • 14
  • 2
    Fragment is not an activity. – Ticherhaz FreePalestine Jul 04 '21 at 10:58
  • 3
    Exactly, to show a fragment in a screen you need a FragmentContainerView -> https://stackoverflow.com/questions/21028786/how-do-i-open-a-new-fragment-from-another-fragment – Manuel Mato Jul 04 '21 at 11:03
  • @ManuelMato Can I use like this, companion object { fun start(fragment: BookingFragment, v: View) { val activity = v.context as AppCompatActivity activity.supportFragmentManager.beginTransaction() .replace(binding.bookingFragment.id, fragment) .addToBackStack(null).commit() } } – Hubby Tiwari Jul 04 '21 at 11:58
  • 1
    I think has no sense this companion to to the navigation from here. If your fragment needs arguments, then I understand the companion object to fetch the bundle arguments, but the navigation musn´t be here. Another weird thing, your fun start(context: BookingFragment) receive a BookingFragment but if you need to open the screen from another fragment, then it won´t be possible, weird approach – Manuel Mato Jul 04 '21 at 17:57

0 Answers0