--------------------------------------------------------------------------------------------------------------------------
Prepared By : Uday Shah (HOD-IT)
E-Mail : udayshah80@gmail.com
Contact No : 7600044051
What is Fragment?
- A fragment is an independent Android
component which can be used by an activity. A fragment encapsulates
functionality so that it is easier to reuse within activities and layouts.
- A fragment runs in the context of an activity,
but has its own life cycle and typically its own user interface. It is
also possible to define fragments without an user interface, i.e.,
headless fragments.
- Android devices exists in a variety of screen
sizes and densities. Fragments simplify the reuse of components in
different layouts and their logic. You can build single-pane layouts for
handsets (phones) and multi-pane layouts for tablets. You can also use
fragments also to support different layout for landscape and portrait
orientation on a smartphone.
- As it is possible to dynamically add and remove
fragments from an activity. The usage of fragments allows to design very
flexible user interfaces.
- The typical example is a list of items in an
activity. On a tablet you see the details immediately on the same screen
on the right hand side if you click on item. On a smartphone you jump to a
new detail screen.
·
onAttach(Activity) : it is called only once when it is
attached with activity.
·
onCreate(Bundle) : It is used to initialize the fragment.
·
onCreateView(LayoutInflater,
ViewGroup, Bundle) : creates and returns view hierarchy.
·
onActivityCreated(Bundle) : It is invoked after the completion of
onCreate() method.
·
onViewStateRestored(Bundle)
: It provides information to the fragment that all the saved state of fragment
view hierarchy has been restored.
·
onStart() : makes the fragment visible.
·
onResume() : makes the fragment interactive.
·
onPause() : is called when fragment is no longer
interactive.
·
onStop() : is called when fragment is no longer
visible.
·
onDestroyView() : allows the fragment to clean up resources.
·
onDestroy() : allows the fragment to do final clean up of
fragment state.
Please Share and Comment it...
:: Best Of Luck ::