please i am building an app which receives notifications and inserts into a database, using parsepushbroadcastreceivers.
Below is my BackgroundActivity
public class BackgroundActivity extends ParsePushBroadcastReceiver {
protected void onPushReceive(Context context, Intent intent) {
String message="";
SQLiteDatabase db;
db = context.openOrCreateDatabase(
"notification.db"
, SQLiteDatabase.CREATE_IF_NECESSARY
, null
);
//CREATE TABLES AND INSERT MESSAGES INTO THE TABLES
String CREATE_TABLE_NOTICES = "CREATE TABLE IF NOT EXISTS notices ("
+ "ID INTEGER primary key AUTOINCREMENT,"
+ "NOTIFICATIONS TEXT)";
db.execSQL(CREATE_TABLE_NOTICES);
Bundle extras = intent.getExtras();
if(extras !=null){
String jsonData = extras.getString("com.parse.Data");
try {
JSONObject notification = new JSONObject(jsonData);
message = notification.getString("alert");
String sql =
"INSERT or replace INTO notices (NOTIFICATIONS) "
+ "VALUES('" + message + "')";
db.execSQL(sql);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Upon advices from the books I read, i learnt it is better to use intentService to deal with the database( sqllite Database). Please I have been reading on the intent Service in my app but to no avail. I would be very much grateful if someone could kindly direct me as to how to implement intentService in the android app. Thanks
Aucun commentaire:
Enregistrer un commentaire