title: I need to implement Notification Reminder in my android app
body: <p><strong>My Requirment:</strong> I want my application to show a reminder notification on every Friday @ 8 am</p>
  
  <p>I have used AlarmManager, BroadcastReceivers to implement my reminder notification. The problem I am getting is, When I set notification time using current system time and Add 2 minutes in it... It works perfectly when I use it in this way, it trigger my notification exactly after 2 minutes.</p>
  
  <p>But,</p>
  
  <p>When I use calender instance to set notification time at specific time of any day, it trigger my reminder notification when ever I start/open my app on my device/emulator and secondly it wont trigger notification at specified time</p>
  
  <p>Following are my classes</p>
  
  <p>Here is my HomeActivity.java</p>
  
  <pre><code>// long when = System.currentTimeMillis()+2*60*1000;         // notification time
  // WHEN I RUN THE ABOVE COMMENTED CODE… THE REMINDER IS TRIGGERD AFTER EXACTLY 2 MINS
  //BUT WHEN I USE THE BELOW CODE USING CALENDER INSTANCE, IT TRIGGER MY REMINDER    IMMIDIETLY WHEN I RUN IT ON MY DEVICE/EMULATOR
  
  
      Calendar calendar =  Calendar.getInstance();            
      //calendar.set(2014,Calendar.getInstance().get(Calendar.MONTH),Calendar.SUNDAY , 8, 00, 00);
      calendar.set(2014,5,1,19,55,00);
  long when = calendar.getTimeInMillis();         // notification time
  
  
  Log.d("time", when+" ");
  
  Intent intentAlarm = new Intent(this, AlarmReceiver.class);
  
  // create the object
  AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
  
   //set the alarm for particular time
  alarmManager.set(AlarmManager.RTC_WAKEUP,when, PendingIntent.getBroadcast(this,1,  intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT));
  </code></pre>
  
  <p>Here is my AlarmReceiver.java</p>
  
  <pre><code>package com.myapp.app;
  
  import java.util.Calendar;
  import java.util.GregorianCalendar;
  
  import android.app.Notification;
  import android.app.NotificationManager;
  import android.app.PendingIntent;
  import android.app.TaskStackBuilder;
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  
  public class AlarmReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
          Calendar now = GregorianCalendar.getInstance();
          int dayOfWeek = now.get(Calendar.DATE);
          if(dayOfWeek != 5 &amp;&amp; dayOfWeek != 7) {
              Notification.Builder mBuilder = 
                      new Notification.Builder(context)
                      .setSmallIcon(R.drawable.ic_launcher)
                      .setContentTitle("Here is my Title")
                      .setContentText("Here is my text");
              Intent resultIntent = new Intent(context, HomeActivity.class);
              TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
              stackBuilder.addParentStack(HomeActivity.class);
              stackBuilder.addNextIntent(resultIntent);
              PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
              mBuilder.setContentIntent(resultPendingIntent);
              NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
              mNotificationManager.notify(1, mBuilder.build());
          }
      }
  }
  </code></pre>
  
  <p>Manifest.xml</p>
  
  <p>I’ve added following in manifest</p>
  
  <pre><code>&lt;receiver
  android:name="com.myapp.app.AlarmReceiver"
  /&gt;
  </code></pre>
  
  <p>Thanks in advance for your help... :)</p>