What are Fragments?
Introduced in Android 3.0 (API level 11), Fragments are a way to modularize your Activities. Fragment allow for sections of your application to be loaded within the same activity. Fragment also inherit the lifecycle of an Activity; when an activity is paused or when it is killed so does the Fragment.
As suggested by Google’s API Guides, Fragments should be designed as a reusable activity. One fragment should not be dependent in another fragment. So, fragments should not be manipulating other fragments.
Fragment can be used on older devices using a Support Library from 1.6 to 2.3.
Why Fragments ?
- Multiple components inside of a single activity.
- Allows for responsive design.
- Don’t have to load a whole activity hence performance increase
Fragment Default Subclasses:
- DialogFragment : Activity managed dialog.
- ListFragment : Displays a list of items that are managed by an adapter. ie: SimpleCusorAdapter
- PreferenceFragment : Displays a hierarchy of Preference object as list similar to PreferenceActivity.