** database **
@Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub db.execSQL("CREATE TABLE " + TABLE_NAME + "(ID INTEGER PRIMARY KEY AUTOINCREMENT, " + key_msg + " STRING, " + key_isread + " STRING)"); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); onCreate(db); }
// ************************** ------- INSERT GCM MESSAGE --------- * *** *********************** //
public void insert_GCM_receive_data(String msg) { String value; SQLiteDatabase db = getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put(key_msg, msg); cv.put(key_isread, "N"); value = cv.toString(); db.insert(TABLE_NAME, null, cv); System.out.println("/n******this is temp table name " + TABLE_NAME + "\nthis is temp msg " + cv + "\nmsg" + msg + "\nval" + value); db.close(); }
// --------------------------------------------- --- ----------------------------------- //
// *********************** ---------- GET WARNING DATA ---------- - * ************************** // public ArrayList get_alert_msg () {
ArrayList<String> name = new ArrayList<String>(); try { SQLiteDatabase db = getWritableDatabase(); Cursor c = null; c = db.rawQuery("SELECT * FROM " + TABLE_NAME, null); System.out.println(c); for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { String str_id = c.getString(0); String str_msg = c.getString(1); String str_read = c.getString(2); Log.e("value", str_id + str_msg + str_read); HashMap<String, String> hm = new HashMap<String, String>(); hm.put("msg", str_msg); hm.put("isread", str_read); name.add(str_msg); } c.close(); db.close(); } catch (Exception e) { Log.e("this not work", "" + e); } return name; }
// method call, as in 2 actions dbHelper.get_alert_msg (); ....
The operation of data manipulation and data extraction is used in a database class ... As soon as you close db after receiving the data. Use a common database method for two activities. Hope this helps you.
Akash pasupathi
source share