android - Restarting phones getting many notification's -


i have simple reminder app. app's problem when restart phone or device, app starts throw many notifications. this source code of java files. onbootreceiver :

public class onbootreceiver extends broadcastreceiver {      private static final string tag = componentinfo.class.getcanonicalname();        @override     public void onreceive(context context, intent intent) {          remindermanager remindermgr = new remindermanager(context);          remindersdbadapter dbhelper = new remindersdbadapter(context);         dbhelper.open();          cursor cursor = dbhelper.fetchallreminders();          if(cursor != null) {             cursor.movetofirst();               int rowidcolumnindex = cursor.getcolumnindex(remindersdbadapter.key_rowid);             int datetimecolumnindex = cursor.getcolumnindex(remindersdbadapter.key_date_time);               while(cursor.isafterlast() == false) {                  log.d(tag, "adding alarm boot.");                 log.d(tag, "row id column index - " + rowidcolumnindex);                 log.d(tag, "date time column index - " + datetimecolumnindex);                  long rowid = cursor.getlong(rowidcolumnindex);                  string datetime = cursor.getstring(datetimecolumnindex);                   calendar cal = calendar.getinstance();                 simpledateformat format = new simpledateformat(remindereditactivity.date_time_format);                   try {                     java.util.date date = format.parse(datetime);                     cal.settime(date);                      remindermgr.setreminder(rowid, cal);                  } catch (java.text.parseexception e) {                     log.e("onbootreceiver", e.getmessage(), e);                 }                  cursor.movetonext();              }             cursor.close() ;             }          dbhelper.close();      } } 

and wakereminderintentservice:

public abstract class wakereminderintentservice extends intentservice { abstract void doreminderwork(intent intent);      public static final string lock_name_static="com.dummies.android.taskreminder.static";     private static powermanager.wakelock lockstatic=null;      public static void acquirestaticlock(context context) {         getlock(context).acquire();     }      synchronized private static powermanager.wakelock getlock(context context) {         if (lockstatic==null) {             powermanager mgr=(powermanager)context.getsystemservice(context.power_service);             lockstatic=mgr.newwakelock(powermanager.partial_wake_lock,                                                         lock_name_static);              lockstatic.setreferencecounted(true);         }         return(lockstatic);     }      public wakereminderintentservice(string name) {         super(name);     }      @override     final protected void onhandleintent(intent intent) {         try {             doreminderwork(intent);         }         {             //getlock(this).release();         }     } } 

can me cancel notification's after device's restart. in code there told schedule notification on specific time, confused why after device's restart many notifications app. can tell me mistake?

update:

onbootreceiver:

import java.text.simpledateformat; import java.util.calendar;  import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.content.pm.componentinfo; import android.database.cursor; import android.util.log;  public class onbootreceiver extends broadcastreceiver {      private static final string tag = componentinfo.class.getcanonicalname();        @override     public void onreceive(context context, intent intent) {          remindermanager remindermgr = new remindermanager(context);          remindersdbadapter dbhelper = new remindersdbadapter(context);         dbhelper.open();          cursor cursor = dbhelper.fetchallreminders();          if(cursor != null) {             cursor.movetofirst();               int rowidcolumnindex = cursor.getcolumnindex(remindersdbadapter.key_rowid);             int datetimecolumnindex = cursor.getcolumnindex(remindersdbadapter.key_date_time);               while(cursor.isafterlast() == false) {                  log.d(tag, "adding alarm boot.");                 log.d(tag, "row id column index - " + rowidcolumnindex);                 log.d(tag, "date time column index - " + datetimecolumnindex);                  long rowid = cursor.getlong(rowidcolumnindex);                  string datetime = cursor.getstring(datetimecolumnindex);                   calendar cal = calendar.getinstance();                 simpledateformat format = new simpledateformat(remindereditactivity.date_time_format);                   try {                     java.util.date date = format.parse(datetime);                     cal.settime(date);                      remindermgr.setreminder(rowid, cal);                  } catch (java.text.parseexception e) {                     log.e("onbootreceiver", e.getmessage(), e);                 }                  cursor.movetonext();              }             cursor.close() ;             }          dbhelper.close();      } } 

setreminder().method:

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); } 

okei have looked in source code , think should cancel in manifest line :

<uses-permission android:name="android.permission.receive_boot_completed" /> 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -