AddEditFragment Overridden Methods onAttach and onDetach

Class AddEditFragment overrides Fragment lifecycle methods onAttach and onDetach (Fig. 8.37) to set instance variable listener to refer to the host Activity (line 49) when the AddEditFragment is attached and to set listener to null (line 57) when the AddEditFragment is detached.

44      // set AddEditFragmentListener when Fragment attached45      @Override46      public void onAttach(Activity activity)47      {48         super.onAttach(activity);49         listener = (AddEditFragmentListener) activity;50      }51 52      // remove AddEditFragmentListener when Fragment detached53      @Override54      public void onDetach()55      {56         super.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.