android - How to make the data to be inside the database without the need to wait for the data to be inserted one by one? -
how dictionaries such merriam dictionary (offline dictionary) when application installed , words there instantly, , time not required insert list of words , definition database? beginner , developing android application consist of 30k words , take around 15+ minutes insert data database before user can search particular data. , looking method can fix this. please tell me way ?
thank you
my guess these apps using sqlite database data need populated. can import populated databases app :
public class databaseadapter {
string db_name = "dbname.db"; string dir = "/data/data/packagename/databases/"; string db_path = dir + db_name; private databasehelper mdbhelper; private sqlitedatabase db; private context context; public databaseadapter(context context) { this.context = context; mdbhelper = new databasehelper(this.context); } class databasehelper extends sqliteopenhelper { private boolean createdatabase = false; @suppresswarnings("unused") private boolean upgradedatabase = false; context context; public databasehelper(context context) { super(context, db_name, null, 1); this.context = context; } public void initializedatabase() { getwritabledatabase(); if (createdatabase) { try { copydatabase(); } catch (ioexception e) { throw new error("error copying database"); } } } private void copydatabase() throws ioexception { inputstream input = context.getassets().open(db_name); outputstream output = new fileoutputstream(db_path); byte[] buffer = new byte[1024]; int length; try { while ((length = input.read(buffer)) > 0) { output.write(buffer, 0, length); } } { try { if (output != null) { try { output.flush(); } { output.close(); } } } { if (input != null) { input.close(); } } } getwritabledatabase().close(); } public void oncreate(sqlitedatabase db) { createdatabase = true; } public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { upgradedatabase = true; } public void onopen(sqlitedatabase db) { super.onopen(db); } } public databaseadapter open() { mdbhelper.initializedatabase(); if (db == null) db = mdbhelper.getwritabledatabase(); return this; } public void close() { db.close(); }
}
you can add methods data database , class can used in activity calling open method data close.
Comments
Post a Comment