Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLiteOpenHelper won't fire onCreate
    primarykey
    data
    text
    <p>I am using this code</p> <pre><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) &gt; 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) { } } </code></pre> <p>And i have been wondering... why do i have to implement that silly hack with SharedPreferences in order for onCreate to fire? Even after wiping application data from the Settings menu and calling getWritableDatabase() onCreate would not fire, leading to crashes coming from the persistence layer. What did i do wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload