Created
July 21, 2014 08:29
-
-
Save showsky/3275bd1e3a40dc1fde56 to your computer and use it in GitHub Desktop.
Content Provider recursive loop error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ----- | |
| private void insertVal(String val, int id) { | |
| ContentValues r = new ContentValues(); | |
| r.put(COL_ID, Integer.valueOf(id)); | |
| r.put(KeyValContract.Columns.VAL, val); | |
| getWriteableDatabase().insert(TAB_VALS, null, r); | |
| } | |
| ----- | |
| /* | |
| Do not call getReadableDatabase or getWriteableDatabase | |
| from an implementation of the onCreate method! | |
| */ | |
| @Override | |
| public void onCreate(SQLiteDatabase db) { | |
| db.execSQL(“CREATE TABLE “ + TAB_VALS + “(“ | |
| + COL_ID + “ integer PRIMARY KEY,” | |
| + KeyValContract.Columns.VAL + “ text)”); | |
| // DON’T DO THIS!!! | |
| insertVal(“bar”, 1); | |
| // ... | |
| } | |
| /* | |
| This won’t work. The call to getWriteableDatabase in insertVal | |
| will cause a recursive loop. | |
| ref: http://stackoverflow.com/questions/15955799/getdatabase-called-recursively | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment