** 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 ALERT 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;
}
//call method like in 2 activity
dbHelper.get_alert_msg();
....
Data manipulation and retrieve operation use with in the Database class...
Once you close the db after retrieve data .
Use common database method to two activity.. I hope this will help you..