0

On my android app I'm using a custom class, that extends from application, to share persistent data between activities and what I want to know is the best way to store that class ? With this I mean; what is the best storage option for my custom class so, if the user reboots or kills the app, I don't lose any information.

Nuno
  • 515
  • 1
  • 5
  • 21
  • 1
    shared prefrences does not clear until and unless you do so. Else database in android is a good option too. – Murtaza Khursheed Hussain Jan 12 '15 at 12:04
  • 1
    Shared preferences is the way to go, for storing options http://developer.android.com/training/basics/data-storage/shared-preferences.html They are cleared on uninstall, or if the user manually clears it. – IAmGroot Jan 12 '15 at 12:04
  • What I want to store are not user options. Maybe a database is the best option. – Nuno Jan 12 '15 at 12:21

1 Answers1

1

Your options:

  1. Parse the object to a JSON string and save it in shared prefrences. google-gson
  2. Serialize and save the object. example
  3. Use a SingleTon to make data accessible. example
Community
  • 1
  • 1
Robin Dijkhof
  • 18,665
  • 11
  • 65
  • 116