Finding Places to Put Data
Depending on the requirements of your application, you may need to store your data in a variety of places. For example, if your application includes music files, users may want to play those files with other music programs — therefore, you'd want to store the files in a location where other applications can access them such as the SD Card (which is considered world readable and writeable). On the other hand, your application may need to store sensitive data such as encrypted username and password details. For these types of applications, you wouldn't share data — you would place it in a secure local storage environment. Regardless of your situation, Android provides various locations where you can persist your data. The most common are as follows:
- Shared preferences: Shared preferences are private data stored in key-value pairs that are available to all components of your application — and that application only. I cover how to use preferences in Chapter 17.
- Internal storage: You can save files on the device's internal storage. By default, files stored in internal storage are private to your application, and other applications cannot access them (neither can the user of the device). When the user uninstalls the application, the private files are removed. You might want to use internal storage as a workspace for when you need to process files at different times during usage of your app over a long period of time.
- Local cache: If you want to cache some ...
Get Android™ Tablet Application Development For Dummies® 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.