经常看到fragment是new出来的,且参数都放在构造方法里面传递,虽然不报错,但总感觉不对劲。
正确方法:
public static MatcherRecordFragment newInstance(int param1) {
MatcherRecordFragment fragment = new MatcherRecordFragment();
Bundle args = new Bundle();
args.putInt(ARG_PARAM1, param1);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = getActivity();
if( null != getArguments()){
state = getArguments().getInt(ARG_PARAM1)+1;
}
}