Android Data Storage
Android provides several ways to store the data. More details can be found from http://developer.android.com/guide/topics/data/data-storage.html
- Shared Preferences
- This provides a quick and easy way to store key-value pair based primitive data across multiple sessions of the app; DOES NOT preserve the data across power cycle.
- Examples/Tutorials
- Internal Storage
- Stores the data on the internal storage of the phone. Preserves the data across the power cycles.
- Files created gets removed when the user uninstalls the app
- This data is app-specific data; Not world readable
- E.g. Example of Internal Storage on Android
- External Storage (e.g. SD Card)
- This is saved/restored in similar way as the internal storage
- HOWEVER -- IT IS WORLD READABLE; So do not save sensitive data
- E.g. External Storage example on Android
- SQLite Databases
- Android has full support for SQLite
- Any database created in the app, can be accessed by the name from any class in the app
- Not outside the app
- To Create a new database, create a subclass of SQLiteOpenHelper
- E.g.
- Cloud storage
- Content provider
- It is the only way to share the data across multiple apps - selectively
- Content provider and Content resolver provides an interface to the app to talk to the Contents, which could be SQLite database or Internal/External storage or on cloud
- Managed Queries is another important concept to understand with ContentProvider with the queries; Managed Queries based cursor will get updated automatically as and when the activity goes through it's life cycle
- Good Blog: http://www.vogella.com/articles/AndroidSQLite/article.html#contentprovider
No comments:
Post a Comment