January 2014
Intermediate to advanced
736 pages
70h 43m
English
Class ContactListFragment overrides Fragment lifecycle methods onAttach and onDetach (Fig. 8.26) to set instance variable listener. In this app, listener refers to the host Activity (line 42) when the ContactListFragment is attached and is set to null (line 50) when the ContactListFragment is detached.
37 // set ContactListFragmentListener when fragment attached38 @Override39 public void onAttach(Activity activity)40 {41 super.onAttach(activity);42 listener = (ContactListFragmentListener) activity;43 }44 45 // remove ContactListFragmentListener when Fragment detached46 @Override47 public void onDetach() ...
Read now
Unlock full access