How best to implement an Android app with large local data?

Viewed 64

I saw a similar question but it was a decade old:

My objective is to create an app (Android/Kotlin) where the users can search/reference/lookup an individual item from a reference 'book'. Something along the lines of a dictionary or book of recipes.

The intent is for the app to be able to work offline, when the user may be anywhere.

As there could be thousands of items/records to reference it would seem to be too much for an array.

Is a Room database a good option and, if so, can a pre-loaded database be included in the package that is uploaded to Google Play? What is best in 2022?

1 Answers

Yes, Room will do exactly what you want, but pre-loading it with data will be tricky (but doable).

You can't technically "pre-load" the database, but what you can do is save all the database objects to a file, using either XML, JSON, or any other format. You will then need to save that file in your project as either an Asset or Raw, and on first app launch, you'll need to read that Asset or Raw resource, parse each record, and save it to the database.

Needless to say, that initial process may take some time, so I'm not sure how good that will be from the user's perspective. But it's definitely pretty straight-forward to implement

Creating the Assets folder

Reading files from Assets

Related