Skip to content

Instantly share code, notes, and snippets.

@IlyaEremin
Created July 31, 2014 05:19
Show Gist options
  • Save IlyaEremin/52108a5f487e791eb71f to your computer and use it in GitHub Desktop.
Save IlyaEremin/52108a5f487e791eb71f to your computer and use it in GitHub Desktop.
static factory in fragments
public class EditContactFragment extends Fragment {
// ...
public static EditContactFragment newInstance(Contact contact){
EditContactFragment fragment = new EditContactFragment();
Bundle contactInfo = new Bundle();
contactInfo.putSerializable(Constants.BUNDLE_CONTACT, contact);
fragment.setArguments(contactInfo);
return fragment;
}
}
public class ClientClass {
// ...
fragment = EditContactFragment.newInstance(contact);
// ...
/*
in every client :\
EditContactFragment fragment = new EditContactFragment();
Bundle args = new Bundle();
args.putSerializable(Constants.BUNDLE_CONTACT, contact);
fragment.setArguments(args);
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment