SUMMARY

In this chapter, you have learned about the three most important components of an Android 3.0 application: activities, fragments, and the Action Bar.

An activity defines the UI of your application, whereas a fragment breaks down an activity into smaller manageable chunks. Depending on the device that the application is currently running on, your application can show or hide different fragments, enabling your application to display the best UI for the current device.

Along with Android 3.0, activities now have the Action Bar, which enables them to display commonly used items, such as options menu items. In the following chapters, you will have a chance to see all these new features in action.

EXERCISES

1. Name the two ways to add fragments to an activity.

2. Name one key difference between a fragment and an activity.

3. How do you add action items to an Action Bar?

Answers to the Exercises can be found in Appendix C.

WHAT YOU LEARNED IN THIS CHAPTER

TOPIC KEY CONCEPTS
Activity Contains the UI of your Android application.
Life cycle of an activity An activity is destroyed when the user presses the Back button. Otherwise, it goes into the background when it loses visibility. To preserve the state of an activity, handle its onPause() event and restore it in the onStart() or onResume() events.
Fragment A fragment is a mini-activity, with its own life cycle. Fragments are embedded in activities.
Manipulating fragments programmatically You need to use the FragmentManager ...

Get Beginning Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.