This is my Activity code,
Long time = new GregorianCalendar().getTimeInMillis()+20000;//Setting alarm after 20 sec
Intent intentAlarm = new Inte
The reason can be Doze mode introduced in Android 6.0 Marshmallow. Use setAlarmclock() instead of set(). It's designed specifically for alarm clocks and may be able to cut through doze. There are a few adb commands you can use to manually put a phone into doze or app standby mode:
https://developer.android.com/preview/features/power-mgmt.html
If that isn't able to wake your app up, there's the surefire method setExactAndAllowWhileIdle() is designed to wake the phone from doze no matter what. Worst case scenario, you can wake your app up with this method and use the wakeup to schedule the next alarm.
Reference: How to make Alarm Manager work when Android 6.0 in Doze mode?