DetailsFragment Overridden Methods onAttach and onDetach
Class DetailsFragment
overrides Fragment
lifecycle methods onAttach
and onDetach
(Fig. 8.44) to set instance variable listener
when the DetailsFragment
is attached and detached, respectively.
45 // set DetailsFragmentListener when fragment attached46 @Override47 public void onAttach(Activity activity)48 {49 super.onAttach(activity);50 listener = (DetailsFragmentListener) activity;51 }52 53 // remove DetailsFragmentListener when fragment detached54 @Override55 public void onDetach()56 {57 super.onDetach();58 listener = null;59 }60
Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.