Skip to content

Instantly share code, notes, and snippets.

@ipereziriarte
Created May 24, 2013 09:12
Show Gist options
  • Save ipereziriarte/5642308 to your computer and use it in GitHub Desktop.
Save ipereziriarte/5642308 to your computer and use it in GitHub Desktop.
Fragment initialization, best practices recommendations from Google IO/13
class Name extends Fragment {
// Key to find our state in a bundle
private static String ARG_STATE = "arg-state";
private Parcelable state;
/**
* Empty constructor
*
* **/
public Name() {
// Do nothing
super();
}
static Name newInstance(Parcelable state) {
Bundle bundle = new Bundle();
// State is a parcelable
bundle.putParcelable(ARG_STATE, state);
Name name = new Name();
name.setArguments(bundle);
return name;
}
public void onCreate(... ) {
Bundle args = getArguments();
state = args.getParcelabe(ARG_STATE);
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment