Chapter 2

Activities, Fragments, and Intents

WHAT YOU WILL LEARN IN THIS CHAPTER

  • The life cycles of an activity
  • Using fragments to customize your UI
  • Applying styles and themes to activities
  • How to display activities as dialog windows
  • Understanding the concept of intents
  • Using the Intent object to link activities
  • How intent filters help you selectively connect to other activities
  • Displaying alerts to the user using notifications

In Chapter 1, you learned that an activity is a window that contains the user interface of your application. An application can have zero or more activities. Typically, applications have one or more activities; and the main purpose of an activity is to interact with the user. From the moment an activity appears on the screen to the moment it is hidden, it goes through a number of stages, known as an activity’s life cycle. Understanding the life cycle of an activity is vital to ensuring that your application works correctly. In addition to activities, Android 4.0 also supports a feature that was introduced in Android 3.0 (for tablets): fragments. Think of fragments as “miniature” activities that can be grouped to form an activity. In this chapter, you will learn about how activities and fragments work together.

Apart from activities, another unique concept in Android is that of an intent. An intent is basically the “glue” that enables different activities from different applications to work together seamlessly, ensuring that tasks can be performed as though ...

Get Beginning Android™ 4 Application Development 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.