jeudi 10 décembre 2015

Please, find any errors in my reasoning about JSON and DB use in my android app

i didn't really knew how to ask :)

I am making an app with some lists and pages. Not heavy. Small amount of data. However data can change. So every time when app is started again it downloads JSON. Small JSON. Download and parsing are done in AsynchTask doInBackground. When i parse JSON i am immediately creating ArrayList ( i don't know how many elements) -- > then an array --> clearing ArrayList.

So i have an array full of precious data. It is stored in the static var. So if i need that data somewhere in my app, i am just calling it without creating an object --> ClassName.myArray[i].getSomething

I do not know if it is safe to store and use the data like that in static vars. Its my first android app. So it's also my first question is it safe? for example, those var won't be never cleaned until an app is used, if smartphone needs memory?

I decided to create a DB, where all the data received with JSON will be saved. So if network is not available APP is still working, maybe with outdated data, but working.

What i have done already: when i'm parsing JSON i do now 2 things inside for each(in AsynchTask doInBackground): - filling an arralist one item after another; - filling database one row after another with the same data.

But i am still using static var with an array for fullfilling my activities.

I don't know what should i do next. Probably i'll put a JSON inside assets. And when app is first time started it will create a database with that data. If there will be new data, it will be downloaded in JSON and that data in database will be overriden.

My doubts - since when at first run of the app will be created a DB with tables ( filled with actual data at release time). How should i populate my pages? Is it ok now to fill static vars from database and use them ( like before i used them too but filling with json data from internet). But in that case when to perform update. if i load data from database into static vars and in that moment there is update and data is writing to db, it will be a disaster ( or not? )

Aucun commentaire:

Enregistrer un commentaire