ContactListFragment Overridden Methods onAttach and onDetach

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() ...

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.