Using the static factory method is intended not only for the fragment, but also for its creation, adapter and other classes. With this approach, you simply control the creation of the object.
One of the benefits is simply increased grip by encapsulating the package keys.
class FragmentFoo extends Fragment{
}
If you want to send a packet to this fragment from the outside
Bundle bundle = new Bundle();
bundle.putString("name","Foo");
Fragment fragment = new FragmentFoo();
fragment.setArgs(bundle);
, "" , , , . , , . -, . , , , ,
factory, . , , , , , . .
class FragmentFoo extends Fragment{
private static final String KEY_NAME = "name";
private String name;
public static Fragment newInstance(String name){
Bundle bundle = new Bundle();
bundle.putString(KEY_NAME, "name");
Fragment fragment = new FragmentFoo();
fragment.setArgs(bundle);
return fragment;
}
}