I want to know that is it a good practice to set the objects directly when creating a new Fragment like in the example below or should we always make our object Parcelable and pass through intent?
public class sample extends Fragment {
private Object obj1;
public static sample newInstance(Object obj) {
sample fragment = new sample();
fragment.setObj1(obj);
return fragment;
}
public void setObj1(Object obj1) {
this.obj1 = obj1;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
return super.onCreateView(inflater, container, savedInstanceState);
}
}
In either case, it will be helpful if someone could give me reasons why one is better than the other?