title: Set a periodic notification in android
body: <p>i am trying to create a periodic notification in android, and i have almost achieved it, the problem is that with my code it opens the app instead of creating the notification, here is my code:</p>
  <pre><code>NotificationCompat.Builder mBuilder =
             new NotificationCompat.Builder(this)
                     .setSmallIcon(R.mipmap.ic_launcher)
                     .setContentTitle(this.getText(R.string.notificationMessage))
                     .setContentText(&quot;&quot;)
                     .setAutoCancel(true);
  
      Intent resultIntent = new Intent(this, MainActivity.class);
  
      // Because clicking the notification opens a new (&quot;special&quot;) activity, there's
      // no need to create an artificial back stack.
      PendingIntent resultPendingIntent =
             PendingIntent.getActivity(
                     this,
                     0,
                     resultIntent,
                     PendingIntent.FLAG_UPDATE_CURRENT
             );
      mBuilder.setContentIntent(resultPendingIntent);
  
      NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
      mNotifyMgr.notify(1,mBuilder.build());
  
  
      AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
  
      Calendar calendar = Calendar.getInstance();
      calendar.set(Calendar.HOUR_OF_DAY, 07);
      calendar.set(Calendar.MINUTE, 00);
      calendar.set(Calendar.SECOND, 00);
  
      alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 24 * 60 * 60 * 1000, resultPendingIntent);  //set repeating every 24 hours
      
  </code></pre>
  <p>UPDATED CODE:</p>
  <p>class Main Activity:</p>
  <pre><code>PendingIntent servicePendingIntent = PendingIntent.getService(this, 0, new Intent(this, NotificationService.class), PendingIntent.FLAG_CANCEL_CURRENT );
  
      AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
  
      Calendar calendar = Calendar.getInstance();
      calendar.set(Calendar.HOUR_OF_DAY, 15);
      calendar.set(Calendar.MINUTE, 20);
      calendar.set(Calendar.SECOND, 00);
  
      alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 24 * 60 * 60 * 1000, servicePendingIntent);  //set repeating every 24 hours
      
  </code></pre>
  <p>class NotificationService:</p>
  <pre><code>public class NotificationService extends IntentService {
  
      /**
       * Creates an IntentService.  Invoked by your subclass's constructor.
       *
       * @param name Used to name the worker thread, important only for debugging.
       */
      public NotificationService(String name) {
          super(name);
      }
  
      @Override
      protected void onHandleIntent(Intent intent) {
  
          Log.d(&quot;NotificationService&quot;, &quot;onHandleIntent&quot;);
  
          NotificationCompat.Builder mBuilder =
                  new NotificationCompat.Builder(this)
                          .setSmallIcon(R.mipmap.ic_launcher)
                          .setContentTitle(this.getText(R.string.notificationMessage))
                          .setContentText(&quot;&quot;)
                          .setAutoCancel(true);
  
          Intent resultIntent = new Intent(this, MainActivity.class);
  
          // Because clicking the notification opens a new (&quot;special&quot;) activity, there's
          // no need to create an artificial back stack.
          PendingIntent resultPendingIntent =
                  PendingIntent.getActivity(
                          this,
                          0,
                          resultIntent,
                          PendingIntent.FLAG_UPDATE_CURRENT
                  );
          mBuilder.setContentIntent(resultPendingIntent);
  
          NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
          mNotifyMgr.notify(1,mBuilder.build());
  
  
  
      }
  
  }
  </code></pre>