android - Database objects not getting executed -
i running following thread in service. but, if have 3 or 4 rows of data in database, last 1 not executed. if having 4 rows of data, 3 gets executed. can tell me reason this?
new thread(new runnable() { @override public void run() { list<greetings>greetings = db.getallgreetings(); if(db.getgreetingscount()>0) { { (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 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 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;
the getallgreetings andgetgreetingscount class shown below
public list<greetings> getallgreetings() { list<greetings> greetinglist = new arraylist<greetings>(); // select query string selectquery = "select * " + table_greetings; sqlitedatabase db = this.getwritabledatabase(); cursor cursor = db.rawquery(selectquery, null); // looping through rows , adding list if (cursor.movetofirst()) { { greetings greeting = new greetings(); greeting.setid(integer.parseint(cursor.getstring(0))); greeting.setdate(cursor.getstring(1)); greeting.setphonenumber(cursor.getstring(2)); greeting.settime(cursor.getstring(3)); greeting.setmessage(cursor.getstring(4)); // adding contact list greetinglist.add(greeting); } while (cursor.movetonext()); } cursor.close(); db.close(); // return greeting list return greetinglist; } public int getgreetingscount() { string countquery = "select * " + table_greetings; sqlitedatabase db = this.getreadabledatabase(); cursor cursor = db.rawquery(countquery, null); int = cursor.getcount(); cursor.close(); db.close(); // return count return a; }
Comments
Post a Comment