I am using AlarmManager in order to set alarm. I have a Service, and in that Service I have a Broadcast Receiver.
The problem is, when selected time and date comes, receiver cannot receive it.
onStart part of my Service class, and where is register my receiver:
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;
}
onReceive Method for receiver:
    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!"); ...}
Part that I run service and set alarm with AlarmManager:
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);
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.adama.wifiv2_spinner">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-feature android:name="android.hardware.wifi" />
<uses-permission android:name="android.permission.VIBRATE"/>
<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">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <service android:name=".BrService"/>
</application>
What am I missing?
I am trying this since I want receive it even user closes the app.