Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The concept of fragments is relatively new to Android. A fragment is simply a block of UI, with its own lifecycle, that can be reused within different activities. Fragments allow developers to create highly modular user interface components that can change dramatically based on screen sizes, orientation, and other aspects of the display that might be relevant to the design.
Table 3.3 shows some important lifecycle calls that are sent to the Fragment class.
Table 3.3. Key Fragment Lifecycle Callbacks
Although the lifecycle of a fragment is similar to that of an activity, a fragment only exists within an activity. A common example of fragment usage is to change the UI flow between portrait and landscape modes. If an interface has a list of items and a details view, the list and the details could both be fragments. In portrait orientation, the screen would show the list view followed by the details view, both full screen. But, in landscape mode, the view could show the list and details side-by-side.