And fix a formatting issue

This commit is contained in:
Bradlee Speice 2014-08-02 22:25:53 -04:00
parent 4baf873ce6
commit 3fe3f64fa8

View File

@ -129,34 +129,34 @@ To demonstrate the principle, we need to add only a single class:
**OGHolder.java** **OGHolder.java**
{% highlight java %} {% highlight java %}
public class OGHolder extends Fragment { public class OGHolder extends Fragment {
private final static String TAG = "OGHolder"; private final static String TAG = "OGHolder";
private ObjectGraph mObjectGraph; private ObjectGraph mObjectGraph;
// Use FragmentActivity for the support library // Use FragmentActivity for the support library
public static OGHolder get(Activity activity) { // 1 public static OGHolder get(Activity activity) { // 1
// Use getSupportFragmentManager for support library // Use getSupportFragmentManager for support library
FragmentManager manager = activity.getFragmentManager(); FragmentManager manager = activity.getFragmentManager();
OGHolder holder = (OGHolder) manager.findFragmentByTag(TAG); // 2 OGHolder holder = (OGHolder) manager.findFragmentByTag(TAG); // 2
if (holder == null) { if (holder == null) {
holder = new OGHolder(); holder = new OGHolder();
manager.beginTransaction().add(holder, TAG).commit(); manager.beginTransaction().add(holder, TAG).commit();
} }
return holder; return holder;
} }
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setRetainInstance(true); // 3 setRetainInstance(true); // 3
} }
public void persistGraph(ObjectGraph graph) { public void persistGraph(ObjectGraph graph) {
mObjectGraph = graph; mObjectGraph = graph;
} }
public ObjectGraph fetchGraph() { public ObjectGraph fetchGraph() {
return mObjectGraph; return mObjectGraph;
} }
} }
{% endhighlight %} {% endhighlight %}