Android Development Slides Lec 06 GCUF
Android Development Slides Lec 06 GCUF
Development
Lecture # 06
M. Javed Iqbal
Fragments
A Fragment represents a reusable
portion of your app's. A fragment defines
and manages its own layout, has its own
lifecycle, and can handle its own input
events. Fragments cannot live they must
be hosted by an activity or another
fragment.
According to the Android
documentation, a fragment is a part of
applications user interface that is bound
to an activity. Fragments have their
lifecycle and layouts or UI
components. Fragments help improve
your UI design, pass data between
different screens, and adapt to different
device configurations.
In a small-screen device an activity
typically fills the entire screen,
displaying the various views that
make up the user interface of an
application. The activity is
essentially a container for views.
However, when an activity is
displayed in a large-screen device,
such as on a tablet, it is somewhat
out of place.
Because the screen is much bigger,
all the views in an activity must be
arranged to make full use of the
increased space, resulting in
complex changes to the view
hierarchy.
A better approach is to have
“mini-activities,” During runtime, an
activity can contain one or more of
these mini-activities, depending on
the screen orientation in
which the device is held, these
mini-activities are known as
fragments.