I have an activity, where a user selects date and time, and the date is entered into the sqlite database. From the activity, I am starting an IntentService like below
Intent intents = new Intent (this,AlarmIntentService.class);
startService(intents);
In the intentservice, I am comparing those data from sqlite database to the current system time, and broadcasting an alarm.
It works fine, when I call the intentservice, first time, with one entry into the database. But, when the user inserts the second data into the sqlite database, and starts the Intentservice, it doesn't work.
Is there anyway to update the passed intentservice with the new data?
The intentservice onhandleintent is described below
final AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
final SqliteController db = new SqliteController(getApplicationContext());
List<Greetings> greetings = db.getAllGreetings();
int k = db.getGreetingsCount();
String p = String.valueOf(k);
Log.d("p", p);
if (db.getGreetingsCount() >= 0) {
do {
for (Greetings g : greetings) {
Calendar cal = Calendar.getInstance();
d1 = cal.get(Calendar.DAY_OF_MONTH);
d2 = cal.get(Calendar.MONTH);
d3 = cal.get(Calendar.YEAR);
t1 = cal.get(Calendar.HOUR);
t2 = cal.get(Calendar.MINUTE);
t3 = cal.get(Calendar.AM_PM);
if (t3 == 1) {
t4 = "PM";
} else {
t4 = "AM";
}
tc = String.valueOf(t1) + " : " + t2 + " " + t4;
d = String.valueOf(d3) + "-" + String.valueOf(d2 + 1) + "-" + String.valueOf(d1);
cdt = d + "\t" + tc;
time = g.getTime();
date = g.getDate();
phone = g.getPhoneNumber();
msg = g.getMessage();
id = g.getID();
dnt = date + "\t" + time;
if (dnt.equals(cdt)) {
Intent aint = new Intent(getApplicationContext(), AlarmReceiver.class);
aint.putExtra("msg", msg);
aint.putExtra("phone", phone);
aint.putExtra("id", id);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), id, aint, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
showNotification();
db.deleteGreetings(g);
}
}
k = db.getGreetingsCount();
} while (k != 0);
Aucun commentaire:
Enregistrer un commentaire