In this case I believe the newInstance
method is just a static factory method for the empty constructor so has no effect (though without the source code available we cannot know for sure), i.e. it is probably something like:
public static SupportMapFragment newInstance() {
return new SupportMapFragment();
}
So why does it exist?
- For consistency with the other
newInstance(GoogleMap)
method most likely - In theory the method could return a sub-class of
SupportMapFragment
, perhaps one optimised for the device or platform - In case any arguments need to be set (perhaps now or in the future)
Because of the last point, it is generally a good practice to always use static factories when creating fragments, in the future it could be modified to:
public static SupportMapFragment newInstance() {
SupportMapFragment fragment = new SupportMapFragment();
Bundle args = new Bundle();
args.putBoolean("secretOptionNotEnabledWithNormalConstructor", true);
fragment.setArguments(args);
return fragment;
}