S
S
Sasha Brahms2016-08-03 08:24:31
Android
Sasha Brahms, 2016-08-03 08:24:31

Where to store data before writing to the database?

Hello everyone ..
There is a lot of information and when installing the application I will write it to the database, where to store it before writing it to the database?
The choice fell on res/values ​​-> string-array, but here's the problem, how to get this resource?
outside Activity getResources does not work..
Please tell me how to be here?
MB pass activity context and there already:
ctx.getRes... ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan, 2016-08-03
@Dlike

Store the ready-made sqlite database in assets and copy it to /packagename/database the first time you run it, the easiest way.

A
Alexander Farber, 2016-08-11
@afarber

Add android-sqlite-asset-helper to build.gradle:

dependencies {
    ......
    compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
}

For example, I am working on a word game and I store the dictionary in two text files.
I wrote a script that creates SQL tables and then loads these words into a sqlite file:
#!/bin/sh

DATABASE=/tmp/words.db
SCRIPT_DIR=`dirname $0`
DESTINATION=$SCRIPT_DIR/../android/Slova/app/src/main/assets/databases/words.db.gz

rm -f $DATABASE
echo ".read android.sql" | sqlite3 -echo $DATABASE 
perl $SCRIPT_DIR/encode-words-for-sqlite.pl < $SCRIPT_DIR/nouns.txt > /tmp/nouns-encoded.txt
perl $SCRIPT_DIR/encode-words-for-sqlite.pl < $SCRIPT_DIR/verbs.txt > /tmp/verbs-encoded.txt
echo ".import /tmp/nouns-encoded.txt words_nouns" | sqlite3 -echo $DATABASE 
echo ".import /tmp/verbs-encoded.txt words_verbs" | sqlite3 -echo $DATABASE 
gzip -vc $DATABASE > $DESTINATION

You can also write a similar .bat file for Windows.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question