1

I am storing my data structure values in SharedPreferences in onPause() methode of activity The SP.xml file size becomes 25K , will there be any effect of doing this storing in onPause() method if yes then What should I do to Store may datastructure in SharedPreferences .

Custadian
  • 845
  • 1
  • 11
  • 37
Tushar
  • 1,122
  • 1
  • 13
  • 28
  • Why don't you store it on Application Directory ??. It is private and only accessible by your app only – Brijesh Thakur Jun 27 '13 at 05:22
  • @BrijeshThakur And you can also make `SharedPreferences` as private. Don't you? – Pankaj Kumar Jun 27 '13 at 05:38
  • 1
    Yes but It's not recommended to store large data using Shared Preferences. You can read page for more information : http://developer.android.com/guide/topics/data/data-storage.html#pref – Brijesh Thakur Jun 27 '13 at 05:41
  • @BrijeshThakur Is 25K is large Data for Shared Preferences Is there any general file size limit or no. of data types stored limit for Shared Preferences – Tushar Jun 27 '13 at 05:56
  • 25K is still Ok. But I would recommend for Private App Directory. – Brijesh Thakur Jun 27 '13 at 06:00

3 Answers3

1

25k is not extremely large but I still wouldn't recommend it. Depending on the needs and complexity of your app, you could look into an SQLite database or serialize your data and put it in an internal file.

Anup Cowkur
  • 20,443
  • 6
  • 51
  • 84
  • I have total 100s of variable in 5 classes sowhile serializing class do I need to serialize each of its variable ? – Tushar Jun 27 '13 at 06:11
  • Yes. Anything you need to save should be serialized. Most built-in java classes have serialization built into them. If you have created custom stuff, you need to write serialization routines for them. – Anup Cowkur Jun 27 '13 at 06:15
  • My Shared Preferences requires 40mS to store my data will it affect any way on my app I am doing it in onPause method ? – Tushar Jun 27 '13 at 10:39
  • 40ms is not too long. Don't worry about it. – Anup Cowkur Jun 27 '13 at 10:47
1

Storing in SharedPreferences lets you access your data virtually everywhere in the same application. Unless you need that data like a token or anything else small but significant you shouldn't do that (bad practice since it makes your application heavy) . It would be better to pass the information in a bundle if you are switching activities or fragment or save it in OnPause() to have the data when the application is resumed or OnSaveInstance() for rotation.

Mouhamed Ndiaye
  • 1,390
  • 2
  • 13
  • 21
0

But unless its too much of structured Data, I would prefer SQLite. Throwing 100 select queries feels odd !!

Prachi
  • 3,584
  • 2
  • 24
  • 39