0

I have a question about performances. Is it usefull to use onSaveInstantState if I use SharedPreferences ?

I mean, if it worth to make a condition to test:

if(savedInstanceState != null) {
    // load with on save instant state
}

else {
    // load with shared preferences
}

or I should always load the datas from SharedPreferences ?

Thank you

  • what is the requirement?? what type of data you are going to store?? Is that data need to be persistent even after app is killed & reopened again?? – Sujay Jul 02 '16 at 16:26
  • It's a collection of objects (I use gson to store in sharedPreferences) and the data needs to be persistant – Herel Adrastel Jul 02 '16 at 16:30

2 Answers2

2

Yes, it is still useful, there are a lot of things that you can't save in the SharedPrefrences dictionary like Lists, Maps or any other custom object.

You should plan on saving information on your SharedPrefrences if you want the data to be persisted through application uses (after your application has been destroyed), and save information onSaveInstanceState bundle if you want to persist data through configuration changes (rotation, font-size change, language change).

Evin1_
  • 12,292
  • 9
  • 45
  • 47
  • Actually, it's a collection of objects so I use Gson to save those datas. By the way, is it worth to use Gson and SharedPreferences (it's a small collection max: 100 items) or use SQLite ? – Herel Adrastel Jul 02 '16 at 16:28
  • That would be another question, but I would deserialize the JSON and save the objects in an SQLite database. – Evin1_ Jul 02 '16 at 16:33
0

If you need data to be persistent across any cases, then go for SQLite.

Sujay
  • 3,417
  • 1
  • 23
  • 25