or Method arguments
Why we should use bundle instead?
Fragment myfragment = new MyFragment(someObjects);
or
myFragment.setSomeObjects(someObjects);
VS
SomeObjects someObjects =(SomeObjects) myFragment.getArguments().getExtras(someObjectsKey);
What are the differences?
Never add params to fragment's constructor. Android can recreate your fragment using its default constructor (parameterless). Thus all properties you set via constructor will become null and your code malfunction or crash. Same with myFragment.setA(a). Calling fragment methods is ok in onAttach though.
Обсуждают сегодня