Default Android Studio generated code:
public static Test newInstance(String param1, String param2) {
Test fragment = new Test();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
public Test() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
Is the null check really useful? In other word, will the argument bundle be destroyed in any case?
Edit: By the way, I cannot understand this either:
@Override
public void onDetach() {
super.onDetach();
mHandler = null;
}
The instance of the fragment is (or going to be) gone, so what is the meaning of setting mHandler to null?