Long gone are the days of the mobile apps with a static UI squished onto a tiny screen. Today's users expect mobile apps to be dynamic and highly interactive. They expect an app to look fantastic when they're looking at it on their medium-resolution smartphone, and that same app needs to look just as fantastic when they switch over to using it on their high-resolution tablet. Apps need to provide rich navigation features. Also, apps need to be adaptive and responsive.
Trying to meet these demands using Android's traditional activity-centric UI design model is difficult. As developers, we need more control than that afforded by activities. We need a new approach: fragments give us that new approach.
In this book, you'll learn how to use fragments to meet the challenges of creating dynamic UIs in the modern world of mobile app development.
Chapter 1, Fragments and UI Modularization, introduces fragments, UI modularization, and the role fragments play in developing a modularized UI. This chapter demonstrates the creation of simple fragments and using fragments statically within activities.
Chapter 2, Fragments and UI Flexibility, builds on the concepts introduced in the previous chapter to provide solutions to specific differences in device layouts. This chapter explains how to use adaptive activity layout definitions to provide support for a wide variety of device form factors, with a small set of fragments that automatically rearrange based on the current device's UI requirements.
Chapter 3, Fragment Lifecycle and Specialization, discusses the relationship of the lifecycle of fragments to that of activities, and demonstrates the appropriate programming actions at the various points in the lifecycle. Leveraging this knowledge, the special purpose fragment classes ListFragment and DialogFragment are introduced to demonstrate their behavior and provide a deeper understanding of how their behavior in the activity lifecycle differs from that of standard fragments.
Chapter 4, Working with Fragment Transactions, explains how to create multiple app screens within a single activity, by dynamically adding and removing fragments using fragment transactions. Topics covered include, implementing back button behavior and dynamically adapting multi-fragment UIs to differences in device characteristics.
Chapter 5, Creating Rich Navigation with Fragments, brings everything together by building on the previous chapters to show how to use fragments to enhance the user's experience through rich navigation features. This chapter demonstrates how to implement a number of navigation features, including screen browsing with swipe-based paging, direct screen access with the drop-down list navigation, and random screen viewing with tabs.