Chapter 7. Preferences, the Filesystem, the Options Menu, and Intents

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. Preferences usually consist of some configuration data as well as a user interface to manipulate that data.

From the user interface point of view, 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 as well as the URL of the server it’s connecting to. This URL is also known as the API root. So, in our case, we’ll have three fields where the user can enter and edit his username, password, and the API root. 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 this information.

All this sounds like a lot of work, but Android provides a framework ...

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