Chapter 3. Multiple Activities and Intents: State Your Intent

Most apps need more than one activity.

So far we’ve just looked at single-activity apps, which is fine for simple apps. But when things get more complicated, just having the one activity won’t cut it. We’re going to show you how to build apps with multiple activities, and how you can get your activities talking to each other using intents. We’ll also look at how you can use intents to go beyond the boundaries of your app and make activities in other apps on your device perform actions. Things are about to get a whole lot more powerful...

Apps can contain more than one activity

Earlier in the book, we said that an activity is a single, defined thing that your user can do, such as displaying a list of recipes. If your app is simple, this may be all that’s needed.

But a lot of the time, you’ll want users to do more than just one thing—for example, adding recipes as well as displaying a list of them. If this is the case, you’ll need to use multiple activities: one for displaying the list of recipes and another for adding a single recipe.

An activity is a single focused thing your user can do. If you chain multiple activities together to do something more complex, it’s called a task.

The best way of understanding how this works is to see it in action. You’re going to build an app containing two activities. The first activity will ...

Get Head First Android Development, 2nd Edition 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.