I see that on google's example for creating a new fragment is through a static method called newInstance. But why aren't we using two constructors to achieve the same thing as below?
ie.
public class MyFragment extends Fragment {
public MyFragment() {
}
public MyFragment(String name) {
Bundle bundle = new Bundle();
bundle.putString(BUNDLE_KEY_NAME, name);
setArguments(bundle);
}
}
public class MyFragment extends Fragment {
public MyFragment() {
}
public static MyFragment newInstance(String name) {
MyFragment myFragment = new MyFragment();
Bundle bundle = new Bundle();
bundle.putString(BUNDLE_KEY_NAME, name);
myFragment.setArguments(bundle);
return myFragment;
}
}