Tutorial 9 (2)
Tutorial 9 (2)
App-specific storage refers to storing data that is private to the application. This data is stored in
either:
b) Shared Storage
Shared storage is used for storing data that can be accessed by other apps or the user.
Examples: Media files (photos, videos, audio) and documents stored in shared directories like
Downloads or Pictures.
Permissions: Apps need specific permissions to read/write to shared storage.
c) Preference
Preferences store small amounts of key-value pairs, typically user settings or preferences.
Managed using SharedPreferences.
d) Database
Databases store structured data in a persistent manner. The most common database used is
SQLite.
1. Data Sensitivity – Sensitive data (e.g., credentials) should be stored in app-specific
storage or encrypted databases.
2. Data Size – Small data fits in SharedPreferences, while large data suits databases
or file storage.
3. Data Structure – Use databases for structured data and file storage for unstructured
data (e.g., media files).
4. Data Accessibility – Private data should use app-specific storage, while shared data
requires shared storage.
5. Persistence – Decide if the data should persist across sessions or can be temporary
(e.g., cache).
6. Performance – Consider efficiency; databases handle queries well but have higher
overhead for small key-value pairs.
Using multiple storage types optimizes data management based on size, sensitivity, and
accessibility.
4. Differences Between Cache Data, SharedPreferences
Data, and Save Instance State Data
Aspect Cache Data SharedPreferences Data Save Instance State
Data
Use Case Caching images, API Storing user settings, app Saving UI state (e.g.,
responses, or temporary configurations, or simple text input, scroll
files for faster access. flags. position) during
rotations.
Accessibility Accessible only to the Accessible only to the app. Accessible only to the
app. app during the
activity lifecycle.
Lifetime Can be cleared by the Persists across app Persists only during
system when storage is restarts until explicitly the activity lifecycle
low or by the app. removed. (e.g., screen
rotation).