If we already have Activity, and a Fragment is just like a sub-activity, then what is the use of having an additional component in Android? So, Fragment is a very interesting component of Android OS which can be used in multiple ways in an android app. Generally, fragments are used to create multi-pane UI in Android apps.Ī Fragment has it's own Layout for the UI(user interface), but we can even define a fragment without any layout, to implement a behavious which has no user interface, more like a background service. If you know Biology, and are aware of the concept of Host and Parasite, then in Android, Activity is the host while a Fragment is a parasite.įragment has its own lifecycle events, which are different from an Activity's lifecylce events.Īn Activity can have any number of fragments in it, although it is suggested to not to use too many fragments in a single activity.Īlso, a fragment is a re-usable component, hence, a single fragment can be included in multiple activities, if required. It functions independently, but as it is linked to the Activity, when an activity is destroyed, the fragment also gets destroyed. Android SDK Manager & required PackagesĪ Fragment in Android is a component which can be used over an activity to define an independent modular UI component attached to the activity.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |