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 and FragmentTransaction classes when adding, removing, or replacing fragments during runtime.
Life cycle of a fragment Similar to that of an activity — you save the state of a fragment in the onPause() event, and restore its state in one of the following events: onCreate(), onCreateView(), or onActivityCreated().
Action Bar Replaces the traditional title bar for older versions of Android.
Action items Action items are displayed on the right of the Action Bar. They are created just like options menus.
Application icon Usually used for going back to the “home” activity of an application. It is advisable to use the Intent object with the Intent.FLAG_ACTIVITY_CLEAR_TOP flag.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset