Files Saving State and Preferences


> Persisting simple application data

> Saving Activity instance data between sessions

> Creating Preference Screens and managing application preferences

> Saving and loading files and managing the local file system

> Including static files as external resources

In this chapter you'll be introduced to two of the simplest but most versatile data persistence techniques in Android — Shared Preferences and local files.

Saving and loading data are essential for most applications. At a minimum, an Activity should save its user interface (UI) state each time it moves into the background. This ensures that the same UI state is presented when the Activity returns to the foreground, even if the process has been killed and restarted before that happens.

It's also likely that you'll need to save user application preferences and UI selections or data entry. Android's nondeterministic Activity and application lifetimes make persisting UI state and application data between sessions particularly important. Android offers several alternatives for saving application data, each optimized to fulfill a particular need.

Shared Preferences are a simple, lightweight key/value pair mechanism for saving primitive application data, most commonly a user's application preferences. Android also provides access to the local file system, through both specialized methods and the normal classes.

Was this article helpful?

0 0
Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide

Post a comment