title: Android - Broadcast Receiver in Service, does not receive
body: <p>I am using AlarmManager in order to set alarm.
  I have a Service, and in that Service I have a Broadcast Receiver.</p>
  
  <p>The problem is, when selected time and date comes, receiver cannot receive it. </p>
  
  <p>onStart part of my Service class, and where is register my receiver:</p>
  
  <pre><code>public int onStartCommand(Intent intent, int flags, int startId) {
      super.onCreate();
  
      IntentFilter intentFilter = new IntentFilter();
      registerReceiver(receiver, intentFilter);
  
      Log.i("com.example.adama", "Service has started!");
  
      return START_STICKY;
  }
  </code></pre>
  
  <p>onReceive Method for receiver:</p>
  
  <pre><code>    public static BroadcastReceiver receiver = new BroadcastReceiver(){
  
      @Override
      public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();
  
          Log.i("com.example.adama", "Receiver has received!"); ...}
  </code></pre>
  
  <p>Part that I run service and set alarm with AlarmManager:</p>
  
  <pre><code>Intent serviceIntent = new Intent(this, BrService.class);
      startService(serviceIntent);
  
      Intent intent = new Intent(this, BrService.class); 
      PendingIntent pendingIntent = PendingIntent.getBroadcast(this,alarmCode++, intent, 0);
      AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
      alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
  </code></pre>
  
  <p>Manifest:</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.adama.wifiv2_spinner"&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
  &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  &lt;uses-feature android:name="android.hardware.wifi" /&gt;
  &lt;uses-permission android:name="android.permission.VIBRATE"/&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;
      &lt;activity android:name=".MainActivity"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;service android:name=".BrService"/&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>What am I missing?</p>
  
  <p>I am trying this since I want receive it even user closes the app.</p>