Android Notification FCM与简单拉 [英] Android Notification FCM vs simple pull

查看:90
本文介绍了Android Notification FCM与简单拉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的Android应用程序,我需要从服务器接收一些通知.通知绝非时间紧迫,只要用户打开应用程序就足以检查新通知,因此根本没有后台活动.

for my android app i need to receive some notifications from a server. The notifications are by no mean time critical and it would be enough to check for new notifications when the user opens the app, so no background activity at all.

我注意到,建议对任何类型的通知使用FCM(Firebase Cloud Messaging)之类的服务.但是,我觉得我将为FCM的一个非常简单的任务引入一个很大的库,这可能会导致电池寿命比仅使用简单的套接字向服务器请求新通知的时间更长.

I noticed, that it is recommended to use a service like FCM (Firebase Cloud Messaging) for any kind of notifications. However, I feel that I would introduce quite a big library for a very simple task with FCM, potentially causing worse battery life than just using simple sockets to ask the server for new notifications.

所以我想知道使用FCM之类的服务还是对我的情况进行简单的通知提取更好.

So I wonder if its better to use a service like FCM or just do simple pulling for notifications in my case.

推荐答案

对于使用fcm的一项非常简单的任务,我会投入大量的库,这可能会导致电池续航时间比仅使用简单的套接字向服务器请求新通知的时间还长.

I feel that I would intodruce quite a big libary for a very simple task with fcm, potentally causing worse battery life than just using simple sockets to ask the server for new notifications.

FCM对所有应用程序使用一个共享的长寿命套接字.手机上的其他应用程序很有可能已经在使用FCM,因此让您的应用程序也使用套接字连接根本不会增加电池使用量.

FCM uses one shared long-lived socket for all apps. There is a fat chance some other app on your phone is already using FCM, so having your app use the socket connection as well would not increase the battery usage at all.

所以我想知道是否最好使用fcm之类的服务,或者只对我的情况进行简单的通知接收.

So I wonder if its better to use a service like fcm or just do simple pulling for notifications im my case.

尽管您的应用程序不需要任何后台推送消息,但我仍然建议您使用FCM通知应用程序任何事件,而不是每次启动应用程序时都询问服务器.轮询与事件的一般原理在这里适用. FCM实施起来并不难.

Although your app does not require any background push messaging, I would still advise you to use FCM to inform the app of any events instead of asking the server every time you start the app. The general principle of polling versus eventing apply here. FCM is not difficult to implement.

这篇关于Android Notification FCM与简单拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆