Вопрос

I have an android project which has a local database, when the application starts it syncs with the web service, I have a JSON file containing Countries, States and Cities of Brazil that is imported into the database as the user need this information to register the address of their customers ...

I can not get this information from the Web, because the proposal of the app is to work offline, and when you have an internet connection to send data to server.

Therefore, I was wondering if there is a way to get this data previously entered in the database and not embed them in the first inicilização, this works, but requires a lot of processing, it takes about 5 minutes on average (this is long ) to do the import.

Any solution?

Thank you!

Это было полезно?

Решение

My previous app has the same problem like this. I give you the solution that I did:

  • Before release your app, you should embed the latest database (imported by json, call db1) in asset folder, then copy it into application database folder (something like /data/your.package/databases) when initializing app, it only takes some seconds. By this way, you can query data and check user login/register normally.
  • Whenever device comes to internet, you just download the latest json data and import it into another database file (call db2) on background.If this progress doesn't have any errors, you can replace db1 file by db2 and it can work properly.

Другие советы

There is no other way to do that but you can minimize your payload using gzipinputstream, big cookie model to sync to your server, fast networking library called volley etc.,

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top