Stay organized with collections
Save and categorize content based on your preferences.
Network traffic sent by server programs to your app can be challenging to
optimize. A solution to this problem is for your app to periodically poll the
server to check for updates. This approach can waste network connection and
power when your app starts up a device's radio, only to receive an answer that
no new data is available. A far more efficient approach would be for the server
to notify your app when it has new data, but figuring out how to send a
notification from your server to potentially thousands of devices was previously
no easy feat.
The Firebase Cloud Messaging (FCM) service solves this communication problem by
allowing your servers to send notifications to instances of your app wherever
they are installed, enabling greater network efficiency and lowering power
usage.
This lesson teaches you how to apply the FCM service to reduce network use for
server-initiated actions and reduce battery consumption.
Send server updates with FCM
Firebase Cloud Messaging (FCM) is a lightweight mechanism used to transmit brief
messages from an app server to your app. Using FCM, your app server uses a
message-passing mechanism to notify your app that there is new data available.
This approach eliminates network traffic that your app would perform, by not
contacting a backend server for new data when no data is available.
An example use of FCM is an app that lists speaker sessions at a conference.
When sessions are updated on your server, the server sends a brief message to
your app telling it updates are available. Your app can then call the server to
update the sessions on the device only when the server has new data.
FCM is more efficient than having your app poll for changes on the server. The
FCM service eliminates unnecessary connections where polling would return no
updates, and it avoids running periodic network requests that could cause a
device's radio to power up. Since FCM can be used by many apps, using it in your
app reduces the total number of network connections needed on a device and
allows the device radio to sleep more often.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2023-07-12 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-07-12 UTC."],[],[],null,["# Optimize server-initiated network use\n\nNetwork traffic sent by server programs to your app can be challenging to\noptimize. A solution to this problem is for your app to periodically poll the\nserver to check for updates. This approach can waste network connection and\npower when your app starts up a device's radio, only to receive an answer that\nno new data is available. A far more efficient approach would be for the server\nto notify your app when it has new data, but figuring out how to send a\nnotification from your server to potentially thousands of devices was previously\nno easy feat.\n\nThe Firebase Cloud Messaging (FCM) service solves this communication problem by\nallowing your servers to send notifications to instances of your app wherever\nthey are installed, enabling greater network efficiency and lowering power\nusage.\n\nThis lesson teaches you how to apply the FCM service to reduce network use for\nserver-initiated actions and reduce battery consumption.\n\nSend server updates with FCM\n----------------------------\n\nFirebase Cloud Messaging (FCM) is a lightweight mechanism used to transmit brief\nmessages from an app server to your app. Using FCM, your app server uses a\nmessage-passing mechanism to notify your app that there is new data available.\nThis approach eliminates network traffic that your app would perform, by not\ncontacting a backend server for new data when no data is available.\n\nAn example use of FCM is an app that lists speaker sessions at a conference.\nWhen sessions are updated on your server, the server sends a brief message to\nyour app telling it updates are available. Your app can then call the server to\nupdate the sessions on the device only when the server has new data.\n\nFCM is more efficient than having your app poll for changes on the server. The\nFCM service eliminates unnecessary connections where polling would return no\nupdates, and it avoids running periodic network requests that could cause a\ndevice's radio to power up. Since FCM can be used by many apps, using it in your\napp reduces the total number of network connections needed on a device and\nallows the device radio to sleep more often.\n| **Note:** When using FCM, your app can pass messages in normal or high priority. Your server should typically use normal priority to deliver messages. Using this priority level prevents devices from being woken up if they are inactive and in a low-power Doze state. Use high priority messages only if absolutely required."]]