title: Android 8.0 - BroadcastReceiver not receiving after a reboot
body: <p>I am developing an app. I am facing a problem. The thing is my code is as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="com.a5corp.weather"&gt;
  
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher_x"
      android:label="@string/app_name"
      android:fullBackupContent="@xml/backup_rules"
      android:theme="@style/AppTheme.NoActionBar"&gt;
      ...
      &lt;service android:name=".service.NotificationService" /&gt;
  
      &lt;receiver
          android:name=".receiver.StartupReceiver"
          android:enabled="true"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  
      &lt;receiver android:name=".receiver.UpgradeReceiver"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MY_PACKAGE_REPLACED" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
      ...
  &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>StartupReceiver:</p>
  
  <pre><code>public class StartupReceiver extends BroadcastReceiver {
  
  @Override
  public void onReceive(Context context, Intent intent) {
          if (intent.getAction() != null &amp;&amp; intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
              ...
              NotificationService.setNotificationServiceAlarm(context, new Prefs(context).getNotifs());
          }
          else
              Log.i("No" , "Boot");
      }
  }
  </code></pre>
  
  <p>UpgradeReceiver:</p>
  
  <pre><code>public class UpgradeReceiver extends BroadcastReceiver {
  
  @Override
  public void onReceive(Context context, Intent intent) {
      Log.i("In" , UpgradeReceiver.class.getSimpleName());
      NotificationService.setNotificationServiceAlarm(context , new Prefs(context).getNotifs());
  }
  }
  </code></pre>
  
  <p>NotificationService:</p>
  
  <pre><code>public class NotificationService extends IntentService {
  
      private static final String TAG = "NotificationsService";
      Prefs prefs;
      Notification.Builder builder;
  
      public NotificationService() {
          super(TAG);
      }
  
      @Nullable
      @Override
      public IBinder onBind(Intent intent) {
          return super.onBind(intent);
      }
  
      @Override
      protected void onHandleIntent(Intent intent) {
          CheckConnection checkNetwork = new CheckConnection(this);
          if (!checkNetwork.isNetworkAvailable()) {
              return;
          }
  
          ...
  
          try {
              WeatherInfo weather;
              weather = new Request(this).getItems(city, units);
              weatherNotification(weather);
          } catch (IOException e) {
              Log.e(TAG, "Error get weather", e);
          }
      }
  
      public static Intent newIntent(Context context) {
          Log.i("Trigger" , "newIntent");
          return new Intent(context, NotificationService.class);
      }
  
      public static void setNotificationServiceAlarm(Context context,
                                                     boolean isNotificationEnable) {
          Log.i("In" , "Notification Service Alarm");
          Intent intent = NotificationService.newIntent(context);
          PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent,
                  PendingIntent.FLAG_UPDATE_CURRENT);
          AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
          long intervalMillis = AlarmManager.INTERVAL_HOUR;
          if (alarmManager != null)
              if (isNotificationEnable) {
                  alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                          SystemClock.elapsedRealtime(),
                          intervalMillis,
                          pendingIntent);
              } else {
                  alarmManager.cancel(pendingIntent);
                  pendingIntent.cancel();
              }
      }
  
      private void weatherNotification(WeatherInfo weather) {
          Intent intent = new Intent(this, WeatherActivity.class);
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
  
          ...
  
          NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
          assert notificationManager != null;
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {
              String id = "w01", name = getString(R.string.weather_notification_title);
              int importance = NotificationManager.IMPORTANCE_MIN;
              String desc = getString(R.string.weather_notification_description);
  
              NotificationChannel channel = new NotificationChannel(id, name, importance);
              channel.setDescription(desc);
              notificationManager.createNotificationChannel(channel);
              builder = new Notification.Builder(this , id);
          }
          else
              builder = new Notification.Builder(this);
  
          ...
          Notification notification = builder.build();
          notificationManager.notify(0 , notification);
      }
  }
  </code></pre>
  
  <p>The problem is that NotificationService as such works on its own, but this does not get called when the app is upgraded or the phone is rebooted. The fact is this is happening on Android O. As far as I remember, this used to work on Android 7.1 before I upgraded to Android 8.</p>
  
  <p><strong>EDIT 1:</strong> After trying JobIntentService, here is how my code looks now:</p>
  
  <p>UPdated Manifest:</p>
  
  <pre><code>...
  &lt;service android:name=".service.ReactivationService"
              android:permission="android.permission.BIND_JOB_SERVICE"/&gt;
  ...
  </code></pre>
  
  <p>Reactivation Service:</p>
  
  <pre><code>public class ReactivationService extends JobIntentService {
  
      public static final int JOB_ID = 0x01;
  
      public static void enqueueWork(Context context, Intent work) {
          enqueueWork(context, ReactivationService.class, JOB_ID, work);
      }
  
      @Override
      protected void onHandleWork(@NonNull Intent intent) {
          Log.i("In" , "onHandleWork()");
          ....
  
              NotificationService.setNotificationServiceAlarm(this, new Prefs(this).getNotifs());
      }
  }
  </code></pre>
  
  <p>Startup Receiver:</p>
  
  <pre><code>public class StartupReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
          if (intent.getAction() != null &amp;&amp; intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
              Log.i("In" , "getAction()");
              ReactivationService.enqueueWork(context, intent);
          }
          else
              Log.i("No" , "Boot");
      }
  }
  </code></pre>
  
  <p>Upgrade Receiver:</p>
  
  <pre><code>public class UpgradeReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
          if (intent.getAction() != null &amp;&amp; intent.getAction().equals(Intent.ACTION_MY_PACKAGE_REPLACED)) {
              Log.i("In" , "getAction()");
              ReactivationService.enqueueWork(context, intent);
          }
          else
              Log.i("No" , "Upgrade");
      }
  }
  </code></pre>
  
  <p>Now my problem is, the ACTION_MY_PACKAGE_REPLACED works fine and shows up the notification, but ACTION_BOOT_COMPLETED is not showing up the notification. What could be the reason, as I am using the same Service for both the receivers.</p>