1

How do apps like Whatsapp or Messenger send alerts/push notifications to users to let them know they have received a message even when the app is closed or destroyed?

I've done some research before I wrote this question.

  • This SO question recommends a Service and a BroadcastReceiver. But the BroadcastReceiver relates to when the device is booted and I cant imagine a Service being constantly and permanently running to check whether someone has sent messages (that's absurd!). In any case, the example that the ansewr gives does not show how or when the Service will stop running.
  • This SO question appears to suggest an AlarmManager but that solution is non-asynchronous (eg, the notification time has to be pre-set).
  • I've read Android's Notification and Services documentation. None of which appear to address this point.
  • Most of the questions that I find on Google appear to be questions relating to how can the app receive push notifications from a server (ie GCM) rather than the app sending push notifications / alerts to the user. I've currently dismissed those questions as irrelevant as I am trying to send notifications to users rather than receive them from servers.
Community
  • 1
  • 1
Gil
  • 515
  • 2
  • 10
  • 24
  • first of all, how to getting messages from server? – Divyesh Patel Feb 14 '17 at 10:13
  • thanks @Divyesh - i guess my question and that question are the same thing. Ill look into those questions I have previously dismissed and withdraw this question if it is resolved. – Gil Feb 14 '17 at 22:05

1 Answers1

0

I let you look around Firebase Push Notifications enter link description here

There are 2 types of notifs:

  • with the click_action when the app is closed or destroy
  • with data object when the app is open
Rémy
  • 313
  • 3
  • 17