Note that there are some explanatory texts on larger screens.

plurals
  1. POAlarmManager repeating function doesn't work as expected
    primarykey
    data
    text
    <p>I am using the following code to start alarm which should shows notification daily on time set for breakfast</p> <pre><code>public void scheduleBreakfast(Context ctxt,int hours,int minutes,String state) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt); if(prefs.contains("notify_breakfast")){ prefs.edit().putString("notify_breakfast",""+hours+":"+minutes+":"+state).commit(); }else prefs.edit().putString("notify_breakfast","8:0:am").commit(); if(prefs.contains("notifyB")){ if(prefs.getBoolean("notifyB",true) == false) return; }else prefs.edit().putBoolean("notifyB",true).commit(); Log.d("in breakfast","scheduling ...."); mgr = (AlarmManager)ctxt.getSystemService(Context.ALARM_SERVICE); Intent myIntent = new Intent(ctxt, NotificationBreakfast.class); PendingIntent pendingIntent = PendingIntent.getService(ctxt, 0, myIntent, 0); long current_time = System.currentTimeMillis(); Calendar time = Calendar.getInstance(); time.set(Calendar.HOUR_OF_DAY, hours); time.set(Calendar.MINUTE, minutes); time.set(Calendar.SECOND, 0); long limit_time = time.getTimeInMillis(); if (current_time &gt; limit_time) { //nothing } else { //show notification Log.d("breakfast","schedule"); mgr.setRepeating(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(),AlarmManager.INTERVAL_DAY, pendingIntent); } } </code></pre> <p>and the code for notification</p> <pre><code>@Override public void onStart(Intent intent, int startId) { // TODO Auto-generated method stub super.onStart(intent, startId); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); if(prefs.getBoolean("notifyB", true)){ notifyShow(); } } </code></pre> <p>the problem is , it doesn't show notification daily and not in time set for breakfast if time set is 8 am , it may fire at 8 am and also on 8:03 and 8:05 .....</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload