Tuesday, November 27, 2018

Fragment In Android

Android Fragment Tutorial



Android Fragment is the part of activity, it is also known as sub-activity. There can be more than one fragment in an activity. Fragments represent multiple screen inside one activity.
Android fragment life-cycle is affected by activity life-cycle because fragments are included in activity.

Each fragment has its own life cycle methods that is affected by activity life cycle because fragments are embedded in activity.

The Fragment-Manager class is responsible to make interaction between fragment objects.

Fragment Life-Cycle



No.MethodDescription
1)onAttach(Activity)it is called only once when it is attached with activity.
2)onCreate(Bundle)It is used to initialize the fragment.
3)onCreateView(LayoutInflater, ViewGroup, Bundle)creates and returns view hierarchy.
4)onActivityCreated(Bundle)It is invoked after the completion of onCreate() method.
5)onViewStateRestored(Bundle)It provides information to the fragment that all the saved state of fragment view hierarchy has been restored.
6)onStart()makes the fragment visible.
7)onResume()makes the fragment interactive.
8)onPause()is called when fragment is no longer interactive.
9)onStop()is called when fragment is no longer visible.
10)onDestroyView()allows the fragment to clean up resources.
11)onDestroy()allows the fragment to do final clean up of fragment state.
12)onDetach()It is called immediately prior to the fragment no longer being associated with its activity.

Below here is the link of our tutorial video on fragment 


No comments:

Post a Comment