Skip to content

Instantly share code, notes, and snippets.

@basilbeltran
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save basilbeltran/77ce8327b5f99a47ea57 to your computer and use it in GitHub Desktop.
Save basilbeltran/77ce8327b5f99a47ea57 to your computer and use it in GitHub Desktop.
Fragment with arg
public class MFragment extends Fragment {
private DataObject mDataObject;
public static final String EXTRA_M_ID = "com.your.apps.extra_id";
public static MFragment newInstance(UUID id) { // set the args
Bundle args = new Bundle();
args.putSerializable(EXTRA_M_ID, id);
MFragment fragment = new MFragment();
fragment.setArguments(args);
return fragment;}
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
UUID id = (UUID)getArguments().getSerializable(EXTRA_M_ID); // use the args
mDataObject = DataStoreSingleton.get(getActivity()).getObject(id);}
}//class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment