So I am working on my app, and it parses data from the LoL (League of Legends) API, so far so good, but the only problem is that if the user closes the app, and reopens it parses the data again. I want the objects I parsed from the JSON data to be saved, once it initially parses them, instead of redownloading them every time I reopen the app. It slows my app down.
Asked
Active
Viewed 56 times
-1
-
1use a database to store your information, refer sqlite, realm – SaravInfern Aug 22 '16 at 03:06
-
I was wondering if there is some native way in android to do this? Like the apps storage? – daesad Aug 22 '16 at 03:52
-
sqlite is a part of android to store data for offline use [refer here](https://www.sqlite.org/android/doc/trunk/www/index.wiki) – SaravInfern Aug 22 '16 at 03:54
2 Answers
1
There are a few ways to do that, but they all basically doing the same thing: serialize/de-serialize objects. The difference will be mostly what kind of persistence storage and what serialization mechanism are you using.
As for persistence you can use for example file, data base, etc.
Java provides human-unreadable binary serialization. Instead you can use JSON, XML, etc. formats. I assume Java built-in serialization will be the fastest, but it won't be deserialize if your class changed in the mean time.
Local persistence also would allow to map objects you parsed into database and load them pieces by pieces as needed.

C.A.B.
- 465
- 4
- 12
0
Save your JSON data as a string in Android SharedPreferences
. It is the most convenient and fastest method for you.

Muktadir Khan
- 148
- 3
- 17

Dulaj Atapattu
- 448
- 6
- 23
-
-
I am talking about this scenario. In this case shared preferences is faster than a sqlite db – Dulaj Atapattu Aug 22 '16 at 04:00
-
please check this answer by Commonsware http://stackoverflow.com/a/15618511/6414107 – SaravInfern Aug 22 '16 at 04:05
-
@SaravInfern Thanks for the info. A small question. In an android device when you go to Settings -> Apps -> application details you can see a section App Data. What is meant by this data? Only the shared preferences or shared preferences + db – Dulaj Atapattu Aug 22 '16 at 05:34
-
-
SharedPreferences has a tight limit on the amount of data which can be stored in it. – Muktadir Khan Apr 09 '19 at 12:37