So I have a fragment like this:
class MyFragment(val thing: SomeDataObject) : Fragment {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// do stuff using `thing`
}
}
And I create and attach it like this:
val myFragment = MyFragment(SomeDataObject())
supportFragmentManager.beginTransaction()
.replace(R.id.contentFrame, myFragment)
.commit()
Where I take a variable thing
as a parameter - this seems to work, however everything I read about passing arguments to fragments says to do it by creating a bundle and setting arguments
on the fragment instance.
Is there something wrong with doing it the way I defined above or some kind of benefit to using bundles instead?
Just curious as to why everywhere else suggests using seemingly over complicated ways of passing the arguments...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…