android - SQLiteOpenHelper won't fire onCreate -


i using code

public class peopledbhelper extends sqliteopenhelper { public static final string table_name = "person"; public static final string db_path = "/data/data/com.machinarius.labs.preloadedsql/databases/"; public static final string db_name = "preload-test.sqlite";  private static final string db_prefs = "whydoihavetodothisagain?";  private context parent;  public peopledbhelper(context context) {     super(context, db_name, null, 1);      parent = context;     sharedpreferences prefs = context.getsharedpreferences(db_prefs, 0);     if(prefs.getboolean("firstrun", true)) {         prefs.edit().putboolean("firstrun", false).commit();         oncreate(null);     } }  @override public void oncreate(sqlitedatabase sqlitedatabase) {     log.i(getclass().getsimplename(), "oncreate()");     inputstream source;     outputstream destination;     byte[] buffer;      try {         source = parent.getassets().open(db_name);         destination = new bufferedoutputstream(new fileoutputstream(db_path + db_name));         buffer = new byte[512];          while(source.read(buffer) > 0) {             destination.write(buffer);         }          source.close();         destination.flush();         destination.close();     } catch(ioexception ex) {         log.e(getclass().getsimplename(), "ioexception", ex);     } }  @override public void onupgrade(sqlitedatabase sqlitedatabase, int i, int i2) {      } } 

and have been wondering... why have implement silly hack sharedpreferences in order oncreate fire? after wiping application data settings menu , calling getwritabledatabase() oncreate not fire, leading crashes coming persistence layer. did wrong?


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -