Fragments represent behavior in particular portion in an activity.
Fragments must embedded in an activity and they cannot run independently without activity.
fragments having its own life cycle like activity life cycle.
To create fragement, we have to create a sub class of fragment.
Fragments introduced from android 3.0(HoneyComb) onwards
It contains callback methods similar to an activity such as onCreate(), onStart(),onPause() and onStop().
onCreate() - system calls when creating a fragment.Initialize components here.
onCreateView()- system calls when the fragment to draw its user interface for 1st time.
onPause() - system calls when the user is leaving the fragment.
onAttach() - it is called when the fragment is associated with activity.
onActivityCreated()- it is called when the activity's onCreate() is returned.
onDestroyView() - it is called when view hierarchy associated with the fragment is removed.
onDetach() -it is called when the fragment is detached from the activity.
Apart from this we have several call back methods.