title: Android daily notification using alarm manager and service
body: <p>Good day, I would like to make daily notification at ~10:00.</p>
  
  <p>There is my code snippet from main activity onCreate():</p>
  
  <pre><code>  Intent mIntent = new Intent(this, NotifyService.class);
          AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
          PendingIntent pendingIntent = PendingIntent.getService(this, 0, mIntent, 0);
  
          Calendar calendar = Calendar.getInstance();
          calendar.setTimeInMillis(System.currentTimeMillis());
          calendar.set(Calendar.HOUR_OF_DAY, 10);
  
  
          alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000*60*60*24, pendingIntent);
  </code></pre>
  
  <p>This is NotifyService.class:</p>
  
  <pre><code>public class NotifyService extends Service {
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
          NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
          Intent notificationIntent = new Intent(this,HomeActivity.class);
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,0);
          Notification notification = new Notification.Builder(this)
                  .setContentTitle("Horoscope reminder")
                  .setContentText("Check your daily horoscope")
                  .setSmallIcon(R.drawable.notification_icon)
                  .setWhen(System.currentTimeMillis())
                  .setContentIntent(pendingIntent)
                  .build();
          notificationManager.notify(9999, notification);
          return super.onStartCommand(intent, flags, startId);
      }
  
      @Nullable
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
  }
  </code></pre>
  
  <p>And line from AndroidManifest.xml after application tag:         <code>&lt;service android:name=".NotifyService"/&gt;</code></p>
  
  <p>I faced with this problem when app is running the notifications pushes randomly, but when app is closed nothing happens.</p>
  
  <p>Anyway, thank you!</p>