Overridden Fragment Lifecycle Methods onAttach and onDetach

When the ColorDialogFragment is added to a parent Activity, method onAttach (Fig. 7.37, lines 88–96) is called. Line 92 gets a reference to the DoodleFragment. If that reference is not null, line 95 calls DoodleFragment’s setDialogOnScreen method to indicate that the Choose Color dialog is now displayed. When the ColorDialogFragment is removed from a parent Activity, method onDetach (lines 99–107) is called. Line 106 calls DoodleFragment’s setDialogOnScreen method to indicate that the Choose Color dialog is no longer on the screen.

87      // tell DoodleFragment that dialog is now displayed88      @Override89      public void onAttach(Activity activity) ...

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.