Skip to content

Instantly share code, notes, and snippets.

@cribetti
Last active March 12, 2020 15:40
Show Gist options
  • Save cribetti/ab958d52c2e833476c2f8c66047e920c to your computer and use it in GitHub Desktop.
Save cribetti/ab958d52c2e833476c2f8c66047e920c to your computer and use it in GitHub Desktop.
class FragmentFactoryImpl(private val arg: String): FragmentFactory() {
override fun instantiate(classLoader: ClassLoader, className: String): Fragment {
return when (className) {
MyFragment::class.java.name -> MyFragment(arg)
MyFragment2::class.java.name -> {
MyFragment2().apply {
arguments = Bundle().apply {
putString("key", arg)
}
}
}
else -> super.instantiate(classLoader, className)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment