Home > DeveloperSection > Forums > what is Fragment Life cycle in Android
Mark Devid
Mark Devid

Total Post:101

Points:707
Posted on    June-27-2016 4:47 AM

 Android Android 
Ratings:


 1 Reply(s)
 274  View(s)
Rate this:

Hi guys 

Can someone tell me about Fragment Life cycle in Android


Samuel Fernandes
Samuel Fernandes

Total Post:154

Points:1082
Posted on    June-27-2016 4:58 AM

Fragment is a piece of activity for user interface. A single activity can contain multiple fragments and many fragments can be reused in many, different activities. In Activity we can add or remove fragment when application is running and a fragment can be used multiple activities.

In activity fragment has own life cycle and very similar to an android activity lifecycle. Core life cycle of fragment

 

 onAttach(Activity) called once the fragment is associated with its activity.

 

 onCreate(Bundle) called to do initial creation of the fragment.

 

 onCreateView(LayoutInflater, ViewGroup, Bundle) creates and returns the view hierarchy associated with the fragment.

 

 onActivityCreated(Bundle) tells the fragment that its activity has completed its own Activity.onCreate().

 

 onViewStateRestored(Bundle) tells the fragment that all of the saved state of its view hierarchy has been restored.

 

 onStart() makes the fragment visible to the user (based on its containing activity being started).

 

  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.

 

 onDetach()     It is called immediately prior to the fragment no longer being associated with its activity.

 


Don't want to miss updates? Please click the below button!

Follow MindStick