alarmmanager - Android reminer reads only one alarm -


i have reminder app. this source code. problem when set 1 alarm fine. when set example 3 alarm, app reads last alarm, reminds third alarm , ignores first 2 alarms. can me set alarmmanager schedule every notification in specific time?

this remindermanager.java:

import java.util.calendar;  import android.app.alarmmanager; import android.app.pendingintent; import android.content.context; import android.content.intent;  public class remindermanager {      private context mcontext;      private alarmmanager malarmmanager;      public remindermanager(context context) {         mcontext = context;          malarmmanager = (alarmmanager)context.getsystemservice(context.alarm_service);     }      public void setreminder(long taskid, calendar when) {          intent = new intent(mcontext, onalarmreceiver.class);         i.putextra(remindersdbadapter.key_rowid, (long)taskid);           pendingintent pi = pendingintent.getbroadcast(mcontext, 0, i, pendingintent.flag_one_shot);           malarmmanager.set(alarmmanager.rtc_wakeup, when.gettimeinmillis(), pi);     } } 

this remindersdbadapter.java:

import android.content.contentvalues; import android.content.context; import android.database.cursor; import android.database.sqlexception; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; import android.util.log;  /**  * simple reminder database access helper class.   * defines basic crud operations (create, read, update, delete)  * example, , gives ability list reminders  * retrieve or modify specific reminder.  *   */ public class remindersdbadapter {      //     // databsae related constants     //     private static final string database_name = "data";     private static final string database_table = "reminders";     private static final int database_version = 3;      public static final string key_title = "title";     public static final string key_body = "body";     public static final string key_date_time = "reminder_date_time";      public static final string key_rowid = "_id";       private static final string tag = "reminderdbadapter";     private databasehelper mdbhelper;     private sqlitedatabase mdb;      /**      * database creation sql statement      */     private static final string database_create =             "create table " + database_table + " ("                     + key_rowid + " integer primary key autoincrement, "                     + key_title + " text not null, "                      + key_body + " text not null, "                      + key_date_time + " text not null);";         private final context mctx;      private static class databasehelper extends sqliteopenhelper {          databasehelper(context context) {             super(context, database_name, null, database_version);         }          @override         public void oncreate(sqlitedatabase db) {              db.execsql(database_create);         }          @override         public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {             log.w(tag, "upgrading database version " + oldversion + " "                     + newversion + ", destroy old data");             db.execsql("drop table if exists " + database_table);             oncreate(db);         }     }       public remindersdbadapter(context ctx) {         this.mctx = ctx;     }      /**      * open database. if cannot opened, try create new      * instance of database. if cannot created, throw exception      * signal failure      *       * @return (self reference, allowing chained in      *         initialization call)      * @throws sqlexception if database neither opened or created      */     public remindersdbadapter open() throws sqlexception {         mdbhelper = new databasehelper(mctx);         mdb = mdbhelper.getwritabledatabase();         return this;     }      public void close() {         mdbhelper.close();     }       /**      * create new reminder using title, body , reminder date time provided.       * if reminder  created return new rowid      * reminder, otherwise return -1 indicate failure.      *       * @param title title of reminder      * @param body body of reminder      * @param reminderdatetime date , time reminder should remind user      * @return rowid or -1 if failed      */     public long createreminder(string title, string body, string reminderdatetime) {         contentvalues initialvalues = new contentvalues();         initialvalues.put(key_title, title);         initialvalues.put(key_body, body);         initialvalues.put(key_date_time, reminderdatetime);           return mdb.insert(database_table, null, initialvalues);     }      /**      * delete reminder given rowid      *       * @param rowid id of reminder delete      * @return true if deleted, false otherwise      */     public boolean deletereminder(long rowid) {          return mdb.delete(database_table, key_rowid + "=" + rowid, null) > 0;     }      /**      * return cursor on list of reminders in database      *       * @return cursor on reminders      */     public cursor fetchallreminders() {          return mdb.query(database_table, new string[] {key_rowid, key_title,                 key_body, key_date_time}, null, null, null, null, null);     }      /**      * return cursor positioned @ reminder matches given rowid      *       * @param rowid id of reminder retrieve      * @return cursor positioned matching reminder, if found      * @throws sqlexception if reminder not found/retrieved      */     public cursor fetchreminder(long rowid) throws sqlexception {          cursor mcursor =                  mdb.query(true, database_table, new string[] {key_rowid,                         key_title, key_body, key_date_time}, key_rowid + "=" + rowid, null,                         null, null, null, null);         if (mcursor != null) {             mcursor.movetofirst();         }         return mcursor;      }      /**      * update reminder using details provided. reminder updated      * specified using rowid, , altered use title, body , reminder date time      * values passed in      *       * @param rowid id of reminder update      * @param title value set reminder title      * @param body value set reminder body      * @param reminderdatetime value set reminder time.       * @return true if reminder updated, false otherwise      */     public boolean updatereminder(long rowid, string title, string body, string reminderdatetime) {         contentvalues args = new contentvalues();         args.put(key_title, title);         args.put(key_body, body);         args.put(key_date_time, reminderdatetime);          return mdb.update(database_table, args, key_rowid + "=" + rowid, null) > 0;     } } 

it because of pendingintent part, although said

public static pendingintent getbroadcast (context context, int requestcode, intent intent, int flags) 

requestcode private request code sender (currently not used).

it used, need use different requestcodes different pendingintents, or system think 1 pendingintent reset many times, problem here.

discussion here


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -