0

while learning android development I came across the following code section:

/**
 * Static initializer for NetworkFragment that sets the URL of the host it will be downloading
 * from.
 */
public static NetworkFragment getInstance(FragmentManager fragmentManager, String url) {
    NetworkFragment networkFragment = new NetworkFragment();
    Bundle args = new Bundle();
    args.putString(URL_KEY, url);
    networkFragment.setArguments(args);
    fragmentManager.beginTransaction().add(networkFragment, TAG).commit();
    return networkFragment;
}

What would be the benefit compared to using a constructor like so:

public NetworkFragment(FragmentManager fragmentManager, String url) {
    Bundle args = new Bundle();
    args.putString(URL_KEY, url);
    networkFragment.setArguments(args);
    fragmentManager.beginTransaction().add(networkFragment, TAG).commit();
}

References: Original Android Code

Skusku
  • 558
  • 5
  • 11

1 Answers1

0

Fragment need default constructor, to create its objects, it is required, so to pass the argument to ur fragment create static method......., that's is the simple reason