If there is a lot of data that you want to save, you should not use Shared Preferences, as this can become messy. Instead, you should write to internal memory. Here are your options:
**Shared Preferences** Store private primitive data in key-value pairs. **Internal Storage** Store private data on the device memory. **External Storage** Store public data on the shared external storage. **SQLite Databases** Store structured data in a private database. **Network Connection** Store data on the web with your own network server.
The last three are the most difficult, but the first two are very light. Here's how to save internal storage if you have too much data in the general settings:
Note. When a user uninstalls your application, these files are deleted. From docs :
To create and write a private file to internal memory:
1. Call openFileOutput () with the file name and current mode.
2. This returns a FileOutputStream.
3. Write to the file using write ().
4. Close the stream using the close () function.
For instance:
String FILENAME = "hello_file"; String string = "hello world!"; FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE); fos.write(string.getBytes()); fos.close();
Getting data is also very simple:
1. Call openFileInput () and pass it the file name to read. This returns a FileInputStream.
2. Read the bytes from the file using read ().
3. Then close the stream with close ().
General preferences are good for storing simple key value pairs, such as high scores, user preferences, etc. If you want to save the essay that the user has typed, perhaps use external or internal storage.
Let me know if this helped,
Ruchir