0

I'm working on an App for Android and I have to retreive information (JSON) from a URL; save it on the phone and then display the information on a list.

Until now I've managed to retreive the information using Jackson library, but now I wonder which is the best way to keep this information on the phone.

I tried to save it as a file into the Internal Storage but then, when I try to read this file to create a JSON Object again, I get errors and I can't find the file on the phone using ADB Monitor to check what's going on.

Then, I tried to saved into the External Storage, but with Android 6.0 there is new Permission Model which I don't quite understand. I would like to have more time to just implement this but I have a deadline for this task.

My last option is to create a SQLite database. Which I haven't done before and also is taking some time to understand.

I would like to read some recomendations from people with experience because I'm new on Android and I don't know in which of these options to focus.

ngbl
  • 273
  • 1
  • 4
  • 5
  • It may be help you http://stackoverflow.com/a/9460267/1443888 – Gurjit Singh Sep 24 '16 at 17:43
  • how big is the json? – Tasos Sep 24 '16 at 17:44
  • By big do you mean its huge by number of lines or file size? – swapyonubuntu Sep 24 '16 at 17:46
  • The JSON is about 6k objects – ngbl Sep 24 '16 at 17:51
  • and how many objects are you getting? – Tasos Sep 24 '16 at 17:57
  • Hi @Tasos, I saved the whole Json into a List, this is done in an Async task. But I need to find a way to persist this data. An access to it even offline. All I have until now, is a List that I've generated using Jackson in my AsyncTask – ngbl Sep 24 '16 at 18:23
  • check dbflow and GSON sample https://github.com/amorenew/WeatherForecast – amorenew Sep 24 '16 at 18:34
  • more info http://stackoverflow.com/questions/39635749/convert-string-to-json-and-getting-error-java-lang-string-cannot-be-converted-to/39636416#39636416 – amorenew Sep 24 '16 at 18:38
  • if you want an instant working solution, you can save your JSON data in `SharedPreferences`. Check though its storage capacity as it is not meant to save big data. But it I recommend you use database to save on your phone. – user1506104 Sep 24 '16 at 18:44
  • you could Convert the data to a CSV file and save it to a folder -- http://stackoverflow.com/questions/15332450/how-to-save-a-multidimensional-json-array-to-a-csv-file-on-android – Tasos Sep 25 '16 at 06:07
  • If you're going to save a file no need to convert back and forth between CSV and JSON, just save the JSON in a text file. – nasch Sep 26 '16 at 13:43
  • Thanks for your answers. I honestly thought that saving the JSON in a file would be the easiest way. But I encountered two errors while doing this. 1. Internal storage: Can't access the file once is saved. When I tried to parse it to get back my JSON object, I got a parsing error in the first line. 2. External storage: New permission model in Android 6.0 too complicated and I have no time (Learn this would be ideal). – ngbl Sep 26 '16 at 13:44

0 Answers0