Search This Blog

Monday 25 June 2012

Basics about fragments - Android

Android introduces the fragments in version 3.0 (API Level 11) to provide intuitive user interface design for large screen size of tablets.

A fragment is a sub-module of the activity to represent a portion of the user interface of the activity. You can combine multiple fragments in a single activity to build multi-pane user interface. The fragments are generalized components can be use in multiple activities

Fragments has its own life cycle and input events and can add and remove from the activity while the activity is running. The fragment will always included in an activity and also known as sub-activity.
The life cycle of the fragment is directly affected by the lifecycle of the activity hosting the fragment.

All the fragment transactions will be move to the activity back-stack and the back button will be used to invoke the fragment transaction from the back stack.

By dividing the activity layout in multiple fragments, you can design a user interface with multiple views in one screen instead of using multiple activities.

For Example a activity could be divide into two fragments left as a list fragment and right as the details fragment to better navigate the contents in single screen. You should keep the design fragment design modular and reusable and avoid the manipulation of one fragment from another, this way you have a greater flexibility to reuse the fragments.





No comments:

Post a Comment