I am running the following thread in a service. But, if I have 3 or 4 rows of data in the database, the last one does not get executed. If I am having 4 rows of data, only 3 gets executed. Can anyone tell me what is the reason for this?
new Thread(new Runnable() {
@Override
public void run() {
List<Greetings>greetings = db.getAllGreetings();
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";
}
StringBuilder strt = new StringBuilder().append(t1).append(" : ").append(t2)
.append(" ").append(t4);
tc = strt.toString();
StringBuilder builder = new StringBuilder().append(String.valueOf(d3) + "-").append((String.valueOf(d2 + 1)) + "-")
.append(String.valueOf(d1));
d = builder.toString();
cdt = d + "\t" + tc;
//Log.d(cdt, "About to execute MyTask");
time = g.getTime();
date = g.getDate();
phone = g.getPhoneNumber();
msg = g.getMessage();
id = g.getID();
dnt = date + "\t" + time;
//Log.d(dnt, "About to execute MyTask");
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);
db.deleteGreetings(g);
}
}
k = db.getGreetingsCount();
} while ( k !=0 );
}
}
}).start();
return START_NOT_STICKY;
Aucun commentaire:
Enregistrer un commentaire