Java Code Examples for android.app.Activity#openOrCreateDatabase()
The following examples show how to use
android.app.Activity#openOrCreateDatabase() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: styT File: Bookmark.java License: Apache License 2.0 | 5 votes |
public void openMyBookmark(Activity activity) { try { String DBNAME = "MyBookmarkDB"; m_db = activity.openOrCreateDatabase(DBNAME, 0, null); } catch (SQLiteException e) { m_db = null; } }
Example 2
Source Project: pius1 File: Bookmark.java License: GNU Lesser General Public License v3.0 | 5 votes |
public void openMyBookmark(Activity activity) { try { m_db = activity.openOrCreateDatabase(DBNAME, 0, null); } catch (SQLiteException e) { m_db = null; } }
Example 3
Source Project: stynico File: Bookmark.java License: MIT License | 5 votes |
public void openMyBookmark(Activity activity) { try { m_db = activity.openOrCreateDatabase(DBNAME, 0, null); } catch (SQLiteException e) { m_db = null; } }
Example 4
Source Project: LaunchEnr File: NotesUtils.java License: GNU General Public License v3.0 | 4 votes |
static String selectedItem(Activity activity, String[] who, int where, ArrayList<String> column) { //create the notes db SQLiteDatabase notesDB = activity.openOrCreateDatabase("notesDB", MODE_PRIVATE, null); Cursor notesCursor = notesDB.rawQuery("SELECT * FROM " + who[0], null); String selected = ""; if (notesCursor != null && notesCursor.moveToFirst()) { while (!notesCursor.isAfterLast()) { //get items at selected position selected = column.get(where); notesCursor.moveToNext(); } notesCursor.close(); } notesDB.close(); return selected; }
Example 5
Source Project: LaunchEnr File: NotesRecyclerViewAdapter.java License: GNU General Public License v3.0 | 4 votes |
private static void deleteNote(Activity activity, int pos) { SQLiteDatabase notesDB = activity.openOrCreateDatabase("notesDB", MODE_PRIVATE, null); String title = NotesUtils.selectedItem(activity, NoteField.TITLES, pos, notesTitles); String note = NotesUtils.selectedItem(activity, NoteField.NOTES, pos, notesBodies); String date = NotesUtils.selectedItem(activity, NoteField.DATES, pos, notesDates); String priority = NotesUtils.selectedItem(activity, NoteField.PRIORITIES, pos, notesPriorities); String titlesTable, notesTable, datesTable, prioritiesTable, whereClause_title, whereClause_note, whereClause_date, whereClause_priority; String[] whereArgs_title, whereArgs_note, whereArgs_date, whereArgs_priority; //set the names of the tables titlesTable = "titles"; notesTable = "notes"; datesTable = "dates"; prioritiesTable = "priorities"; //set where clause whereClause_title = "title" + "=?"; whereClause_note = "note" + "=?"; whereClause_date = "date" + "=?"; whereClause_priority = "priority" + "=?"; //set the where arguments whereArgs_title = new String[]{title}; whereArgs_note = new String[]{note}; whereArgs_date = new String[]{date}; whereArgs_priority = new String[]{priority}; //delete 'em all notesDB.delete(titlesTable, whereClause_title, whereArgs_title); notesDB.delete(notesTable, whereClause_note, whereArgs_note); notesDB.delete(datesTable, whereClause_date, whereArgs_date); notesDB.delete(prioritiesTable, whereClause_priority, whereArgs_priority); //update data arrays and update the recycler view //remove all the adapter data notesTitles.remove(pos); notesBodies.remove(pos); notesDates.remove(pos); notesPriorities.remove(pos); NotesRecyclerViewAdapter notesRecyclerViewAdapter = new NotesRecyclerViewAdapter(activity, notesTitles, notesBodies, notesPriorities, notesDates); RecyclerView notesRecyclerView = activity.findViewById(R.id.notesRecyclerView); //and update the dynamic list //don't move this method above the db deletion method or you'll get javalangindexoutofboundsexception-invalid-index error notesRecyclerView.getAdapter().notifyDataSetChanged(); notesRecyclerView.setAdapter(notesRecyclerViewAdapter); }
Example 6
Source Project: LaunchEnr File: NotesUtils.java License: GNU General Public License v3.0 | 3 votes |
static ArrayList<String> initNoteElement(Activity activity, String[] who) { //create the notes db SQLiteDatabase notesDB = activity.openOrCreateDatabase("notesDB", MODE_PRIVATE, null); //create a table called ? with a column called ? where notes titles will be stored notesDB.execSQL("CREATE TABLE IF NOT EXISTS " + who[0] + "(id INTEGER PRIMARY KEY AUTOINCREMENT," + who[1] + " varchar);"); ArrayList<String> selected = new ArrayList<>(); Cursor notesDBcursor; notesDBcursor = notesDB.rawQuery("SELECT * FROM " + who[0], null); if (notesDBcursor != null && notesDBcursor.moveToFirst()) { while (!notesDBcursor.isAfterLast()) { //add items to selected field selected.add(notesDBcursor.getString(notesDBcursor.getColumnIndex(who[1]))); notesDBcursor.moveToNext(); } notesDBcursor.close(); } notesDB.close(); return selected; }