Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Aniket Kadam
Aniket Kadam

Posted on • Originally published atMedium on

     

“You may have new messages” — Explained!

The classic notification explained.

TLDR? Notifying you that you have new messages is done on more reliable, more instant networking channel than the channel used to actually download your message.

Keep reading for more detail on what that means.

I worked on two different chat systems for a job once.

One was automated, i.e you asked the server for something and got back a scripted chat.

One was the human kind, where one person sends messages and the other can see and respond.

I built the human kind out withFirebase Realtime Db. It could’ve also been done withRealm which is another service that manages syncing disparate data sources for you.

While this could’ve been built out ourselves, as a startup you don’t want to waste time building things that aren’t core IP.

You’d start off with two simple things, actually get messages to people and notify them when they receive new ones.

With Firebase, we could add these messages to the db, write rules to ensure only the right users had access to them, and simply set thekeep synced on.

Keep synced would do two major major things for us.

  1. Messages would now be available offline and you could even attempt to send them while offline, they’d be sent whenever you did go online.
  2. When you receive new messages, they’d be put into storage and you could access them if you had since gone offline.

Synced distributed databases are kinda like time travel episodes in sci-fi. They have a lot of weird cases all over the place and you take a while to get used to it if you’ve never seen one before.

So, by now you might think. Why even bother with separate mobile app notifications? The data would be synced when the other person sends it right? Shouldn’t we only need the Firebase Realtime DB?

This would be fine if mobile OS developers did one very bad thing, which they don’t. Which is, if apps were allowed to run all the time in the background.

Your app is going to be shut down. Either for memory pressure, or to conserve battery or simply to avoid pointless checks when you’re not using it often.

There could be a new message and people would have received it, if the app ever started up that is.

This can be solved very simply, by sending a push notification!

Push notifications can ‘wake up’ devices in doze if marked high-priority. Android may prioritize them in such a way that a push notification gets throughbut no other networking is allowed at that time. Which means if you tried a subsequent network call it could outright fail.

That’s how the two work together. You might have had enough of a network to get the push notification, which alerts you to the possibility of a message, maybe even a title. But your actual database backing the chat, hasn’t updated yet since it has to operate through a different network channel.

Hence ‘ You may have new messages’.

The next time you see Whatsapp show you that notification, you’ll know what’s happening behind the scenes :)

Networking is complicated and fun and pretty unique for mobile devices. I was jumping up and down when I realised I recreated the situation that makes Whatsapp tell you that in my own chat system.

Ask me any questions by commenting below or sending me a message onTwitter at@AniketSMK !

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

An android dev with ~8 years of experience. I consult and may join fulltime for the right company.
  • Location
    India
  • Work
    Android Developer
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp