My app sends notifications via NotificationManager to the user once every hour. Now it may happen that the screen of the device goes off within that hour, but my notification should still be sent (and ring/vibrate the phone, but not turn on screen). How can I achieve to send a notification even if screen is off (CPU off)? I read about Handler and AlarmManager, but not sure if that’s what I need. Please advise. Thanks.
My app sends notifications via NotificationManager to the user once every hour. Now it
Share
Use
AlarmManagerto get control every hour — whatever you are doing right now is very inefficient.Specifically, you will need to use a
getBroadcast()PendingIntentand a_WAKEUPstyle alarm. This will wake up the phone and give you control inonReceive()of yourBroadcastReceiver, with the device awake untilonReceive()returns. There, you raise yourNotification.