Data Persistance
Data Persistance
SharedPreferences
The SharedPreferences class allows you to save and
retrieve key / value pairs of primitive data types.
We can use the SharedPreferences to save the
primitive data: booleans, floats, ints, longs, and
strings.
These data will persist in the user session (even if
your application is dead).
For an SharedPreferences object to your
application, use one of two methods:
getSharedPreferences (String name, int mode) -
Use if you need several preferences files identified
by name that will be passed in the first parameter.
SharedPreferences
getPreferences (int mode) - Use if you just
need a preferences file for your activity.
To write values:
SharedPrefereces.
File Handling
A File object works well for reading or
writing large amounts of data.
The exact location of the where your files
FileOutputStream
FileInputStream
File Handling
Managing data using SQLite database
◦ Saving data to a database is ideal for repeating or
structured data, such as contact information.
◦ The APIs you'll need to use a database on Android
are available in
the android.database.sqlitepackage.
Create a database using an SQL helper
◦ Once you have defined how your database looks,
you should implement methods that create and
maintain the database and tables. Here are some
typical statements that create and delete a table:
File Handling