Chapter 9. Intents, Action Bar, and More

In this chapter, you will learn how to create preferences for your application, how the filesystem is organized, and how to use intents and the options menu to jump from one activity to another.

Preferences

Preferences are user-specific settings for an application. They usually consist of some configuration data as well as a user interface to manipulate that data.

In the user interface, preferences can be simple text values, checkboxes, selections from a pull-down menu, or similar items. From a data point of view, preferences are a collection of name-value pairs, also known as key-value or attribute-value pairs. The values are basic data types, such as integers, booleans, and strings.

Our micro-blogging application needs to connect to a specific server in the cloud using specific user account information. For that, Yamba needs to know the username and password for that account. So our interface will have two fields where the user can enter and edit the username, and the password. This data will be stored as strings.

To enable our app to handle user-specific preferences, we need to build a screen to enter the information, Java code to validate and process that information, and some kind of mechanism to store the information.

All this sounds like a lot of work, but Android provides a framework to help streamline working with user preferences. First, we’ll define what our preference data looks like in a preference resource file.

To create preferences ...

Get Learning Android, 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.