Thursday, November 14, 2013

What is Fragment ?

Hi Friends!!
Today I am going to discuss about Fragment. Now it is available with new API open source library android-support v4 or v7 or v13.  android-support v13 is the recent api library.

What is Fragment in Android ?

  • A fragment is a class implementing a portion of an activity.
  • A fragment represents a particular operation or interface running within a larger activity.
  • Fragments must be embedded in activities; they cannot run independent of activities.
  • Most fragments define their own layout of views that live within the activity’s view hierarchy.  
  • A fragment has its own life-cycle, closely related to the life-cycle of its host activity. 
  • A fragment can be a static part of an activity, instantiated automatically during the activity’s creation.
  • Or, you can create, add, and remove fragments dynamically in an activity at run-time.

What is Life cycle of Fragment ?

Fragments have a few extra life cycle callbacks managing interaction with the activity:
onAttach(Activity) => Called when the fragment has been associated with the activity. 
 
onCreateView(LayoutInflater, ViewGroup, Bundle) => Called to create the view hierarchy associated   
 with the fragment. 
 
onActivityCreated(Bundle) => Called when the activity’s onCreate() method has returned. 
 
onDestroyView() => Called when the view hierarchy associated with the fragment is being removed. 
 
onDetach() => Called when the fragment is being disassociated from the activity. 
 
 
 
 
 
 
 

No comments:

Post a Comment

Mastering Jetpack Compose: Key Methods for Efficient Android UI Development

Jetpack Compose is a modern toolkit for building native Android UI. It simplifies UI development by providing a declarative approach, making...