Fragment lifecycles

Activities can contain Fragments--self-contained units that contain views and have a lifecycle of their own. However, the lifecycle of a Fragment is bound to the Activity that contains it, so they are also tightly related.

The lifecycle can be seen in the following figure:

A very good briefing and explanation about Fragments can be found at https://developer.android.com/guide/components/fragments.html.

We can see that this is very similar to the lifecycle of an Activity, but there are a few new methods, such as the following:

  • onAttach()
  • onCreateView()
  • onActivityCreated()
  • onDestroyView()
  • onDetach()

It is beyond the scope of this book to cover the use of Fragments in any depth, but you just need to remember that the same rules about leaks that apply for Activities apply for Fragments as well.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.79.241