Created
May 24, 2013 09:12
-
-
Save ipereziriarte/5642308 to your computer and use it in GitHub Desktop.
Fragment initialization, best practices recommendations from Google IO/13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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