android-sqlite
When the SQLiteOpenHelper onCreate method is called?
The documentation says: The database is not actually created or opened until one of getWritableDatabase() or getReadableDatabase() is called.
Get the ID of a new record inserted into a database from the returned Uri
ContentUris.parseId() converts the last path segment to a long.
How can I create a list Array with the cursor data in Android
Go through every element in the Cursor, and add them one by one to the ArrayList. ArrayList<WhateverTypeYouWant> mArrayList = new ArrayList<WhateverTypeYouWant>(); for(mCursor.moveToFirst(); !mCursor.isAfterLast(); mCursor.moveToNext()) { // The Cursor is now set to the right position mArrayList.add(mCursor.getWhateverTypeYouWant(WHATEVER_COLUMN_INDEX_YOU_WANT)); } (replace WhateverTypeYouWant with whatever type you want to make a ArrayList of, and WHATEVER_COLUMN_INDEX_YOU_WANT with the column index … Read more
Is the onUpgrade method ever called?
For those of you who would like to know the exact moment when onUpgrade() gets called, it is during a call to either getReadableDatabase() or getWriteableDatabase(). To those who are not clear how it ensure it gets triggered, the answer is: It is triggered when the database version provided to the constructor of SqLiteOpenHelper is … Read more
Android: SQLite saving string array?
You cannot save String array into Database. But you can use this trick. 1) So you have to convert it into simple String using convertArrayToString(String[] array) method. This will concatenate all elements of string using ‘comma’. 2) When you would retrieve this String back from Database you could convert it back to String array using … Read more