title: BroadcastReceiver not being triggered when app is closed
body: <p>I'm attempting to make it so my app runs some code once per day at 6AM. This works just fine when the app is open and in the foreground, but if the app is closed by swiping it away, the code is never called at the appropriate time.</p>
  
  <p><strong>AlarmReceiver.java</strong> (For testing purposes, I have it just trying to display a Toast to verify it runs)</p>
  
  <pre><code>public class AlarmReceiver extends BroadcastReceiver {
  
      public static final String intentAction = "com.mpagliaro98.action.NOTIFICATIONS";
  
      @Override
      public void onReceive(Context context, Intent intent) {
          if (intent.getAction().equals(intentAction)) {
              Toast.makeText(context, "RECEIVER CALLED", Toast.LENGTH_LONG).show();
          }
      }
  }
  </code></pre>
  
  <p><strong>MainActivity.java</strong> (Where the alarm is being set)</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      ...
  
      private void setRecurringAlarm() {
          // Set this to run at 6am
          Calendar updateTime = Calendar.getInstance();
          updateTime.setTimeZone(TimeZone.getDefault());
          updateTime.set(Calendar.HOUR_OF_DAY, 6);
          updateTime.set(Calendar.MINUTE, 0);
          updateTime.set(Calendar.SECOND, 0);
          updateTime.set(Calendar.MILLISECOND, 0);
  
          // Build the pending intent and set the alarm
          Intent i = new Intent(AlarmReceiver.intentAction);
          PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(),
                  0, i, PendingIntent.FLAG_CANCEL_CURRENT);
          AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
          assert am != null;
          am.setRepeating(AlarmManager.RTC, updateTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pi);
      }
  }
  </code></pre>
  
  <p><strong>AndroidManifest.xml</strong> (Just the relevant parts)</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.SET_ALARM" /&gt;
  
  &lt;receiver
      android:name=".AlarmReceiver"
      android:enabled="true"
      android:exported="true"&gt;
      &lt;intent-filter&gt;
          &lt;action android:name="com.mpagliaro98.action.NOTIFICATIONS" /&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  </code></pre>
  
  <p>I've read through dozens of similar problems to this on this site and elsewhere and I'm seriously at a loss for why this won't work. Any help would be appreciated.</p>