what is Fragment Life cycle in Android

Posted by  Mark Devid
 1633  View(s)
Rate this:

Hi guys 

Can someone tell me about Fragment Life cycle in Android
  1. Re: what is Fragment Life cycle in Android

    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.


      Modified On Apr-11-2018 04:39:04 AM