Home > Software design >  Fragment factory with dialog fragments
Fragment factory with dialog fragments

Time:10-15

Is it okey to instantiate a dialog fragment with FragmentFactory ?

baseActivity.fragmentFactoryImpl.title = title
val testFragment=
            baseActivity.supportFragmentManager.fragmentFactory.instantiate(
                baseActivity.classLoader, TestFragmentDialog::class.java.name
            ) as DialogFragment

CodePudding user response:

Recommend you to use Jetpack Navigation Component

Easy way to manipulate with Fragments and actions between them

The other way is to create MyDialogFragment class and instantiate it where needed. Doc here

CodePudding user response:

FragmentFactory Interface used to control the instantiation of Fragment instances. Implementations can be registered with a FragmentManager via setFragmentFactory.

Useful if you want to initialize the fragment with a custom parameter.

When I look at your code, you don't provide a use case that would require using the fragment Factory.

  • Related