How to change non-default constructor in fragments to default constructor?

android, java

Solution

When you create your fragment, use setArgument():

Bundle args = new Bundle();
// Construct your bundle here
Fragment mFragment = new PlacePickerFragment();
mFragment.setArguments(args);
mFragment.initialize();

And use fragment's default constructor. You may need to call `setPlacePickerSettingsFromBundle()` after you have set the arguments, something like this:

public PlacePickerFragment() {
    super(GraphPlace.class, R.layout.com_facebook_placepickerfragment, args);
}

public void initialize() {
    Bundle args = getArguments();
    setPlacePickerSettingsFromBundle(args);
}

Problem

Code: ``` public PlacePickerFragment() { this(null); } public PlacePickerFragment(Bundle args) { super(GraphPlace.class, R.layout.com_facebook_placepickerfragment, args); setPlacePickerSettingsFromBundle(args); } ``` Hello, I want to remove deprecation warning from code above, is there a way changed it to default constructor?

Original source