Reputation: 43
I'm writing an android weather app, which needs a city information list.
The list is quite long, and spends long time to be downloaded from internet.
So I want to save it in my .apk file, and load it without internet connection, but don't know how.
I tried to save it in a java class, but it's toooo huge and costs much memory.
Are there some ways to solve it? Thx!
Upvotes: 0
Views: 1430
Reputation: 13541
did you look at res/assets?
I assume that you probably have some sort of json/xml data that you want to pre-package with your app if so, then load the json/xml into the res/assets and it'll just be a file included with your apk.
https://developer.android.com/guide/topics/resources/accessing-resources.html
Upvotes: 3
Reputation: 29783
You can store it in SQLite database or use plain text then save it in raw or asset resource in your app project.
For SQLite, try Android SQLiteAssetHelper which will help you with storing data from a predefined database.
Here an excerpt from its README:
An Android helper class to manage database creation and version management using an application's raw asset files.
This class provides developers with a simple way to ship their Android app with an existing SQLite database (which may be pre-populated with data) and to manage its initial creation and any upgrades required with subsequent version releases.
It is implemented as an extension to SQLiteOpenHelper, providing an efficient way for ContentProvider implementations to defer opening and upgrading the database until first use.
Rather than implementing the onCreate() and onUpgrade() methods to execute a bunch of SQL statements, developers simply include appropriately named file assets in their project's assets directory. These will include the initial SQLite database file for creation and optionally any SQL upgrade scripts.
Upvotes: 2
Reputation: 827
you may use arrays
from xml resources. For example
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="cities">
<item>New York</item>
<item>London</item>
<item>Moscow</item>
....
</string-array>
</resources>
Upvotes: 0