O'Reilly logo

Android™ Tablet Application Development For Dummies® by Donn Felker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 17

Working with Android's Preference Framework

In This Chapter

  • Seeing how preferences work in Android
  • Building a preference screen
  • Working with preferences programmatically

I consider myself a power user of computer software, and I'm sure that you're a power user as well. I know that most programs can be configured to suit my needs (for the most part), and I usually go out of my way to find the settings or preferences to set up my favorite configuration for a given program. Allowing your users to do the same in your Android application gives your application an advantage in regard to usability. Thankfully, creating and providing a mechanism to edit preferences in Android are fairly easy processes.

Out of the box, Android provides a robust preference framework that allows you to declaratively as well as programmatically define preferences for your application. Android stores preferences as persistent key-value pairs of primitive data types for you. You are not required to store the values in a file, database, or any other mechanism. The Android preference framework takes the values you provide and commits them to internal storage on behalf of your application. You can use the preference framework to store booleans, floats, ints, longs, and strings. The data persists across user sessions as well — meaning that if the user closes the app and reopens it later, the preferences are saved and can be used again. This is true even if your application is killed.

In this chapter, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required