An update or modification to a Fragment is performed using a

An update or modification to a fragment is performed

This preview shows page 11 - 16 out of 55 pages.

An update or modification to a Fragment is performed using a FragmentTransaction : android.app.FragmentTransaction A number of different actions can be applied to a Fragment using a FragmentTransaction operation, such as the following: A Fragment can be attached or reattached to the parent Activity . A Fragment can be hidden and unhidden from view .
Image of page 11

Subscribe to view the full document.

Managing Fragment Modifications (Cont’d) Perhaps you are wondering how the Back button fits into the Fragment -based user interface design. We know the parent Activity class has its own back stack. As the developer, you can decide which FragmentTransaction operations are worth storing in the back stack and which are not by using the addToBackStack() method of the FragmentTransaction object. In our news application example, we might want each of the articles displayed in the WebViewFragment to be added to the parent Activity class’s back stack so that if the user hits the Back button, he or she traverses the articles already read before backing out of the Activity entirely.
Image of page 12
Attaching and Detaching Fragments with Activities After you have a Fragment that you want to include within your Activity class, the lifecycle of the Fragment comes into play. The following callback methods are important to managing the lifecycle of a Fragment , as it is created and then destroyed when it is no longer used. onAttach() onCreate() onCreateView() onActivityCreated() onStart() onResume() onPause() onStop() onDestroyView() onDestroy() onDetach()
Image of page 13

Subscribe to view the full document.

Attaching and Detaching Fragments with Activities The onAttach() callback method is called when a Fragment is first attached to a specific Activity class. The onCreate() callback method is called when a Fragment is first being created. The onCreateView() callback method is called when the user interface layout, or View hierarchy, associated with the Fragment should be created. The onActivityCreated() callback method will inform the Fragment when its parent Activity class’s onCreate() method has completed. The onStart () callback method is called when the Fragment ’s user interface becomes visible but is not yet active. The onResume() callback method makes the Fragment ’s user interface active for interaction after the Activity has resumed or the Fragment was updated using a FragmentTransaction . The onPause() callback method is called when the parent Activity is paused, or the Fragment is being updated by a FragmentTransaction . It indicates that the Fragment is no longer active or in the foreground.
Image of page 14
Attaching and Detaching Fragments with Activities The onStop() callback method is called when the parent Activity is stopped, or the Fragment is being updated by a FragmentTransaction . It indicates the Fragment is no longer visible.
Image of page 15

Subscribe to view the full document.

Image of page 16
  • Summer '16

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes