Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Firebase Cloud Messaging(FCM): Will subscribeToTopic do automatic retries?

To Subscribe to a topic in an android client we should call:

FirebaseMessaging.getInstance().subscribeToTopic("news");

I want to know what happens if the internet connection is not available at moment that this instruction is executed?

Will google services automatically retry to do subscription when Internet connection become available or we developer should handle this case?

like image 422
VSB Avatar asked Oct 16 '16 10:10

VSB


People also ask

How long does FCM token last?

Ensuring registration token freshness To cover all cases, you should adopt a threshold for when you consider tokens stale; our recommendation is two months. Any token older than two months is likely to be an inactive device; an active device would have otherwise refreshed its token.

How does FCM work on Android?

The FCM backend receives the message request, generates a message ID and other metadata, and sends it to the platform specific transport layer. When the device is online, the message is sent via the platform-specific transport layer to the device. On the device, the client app receives the message or notification.

Is there any limit for FCM?

For Android, you can send up to 240 messages/minute and 5,000 messages/hour to a single device.

Can FCM notification on Android overwrite previous one?

If specified and a notification with the same tag is already being shown, the new notification replaces the existing one in the notification drawer.


1 Answers

Update:

subscribeToTopic() now returns a Task<Void> so you could attach an OnCompleteListener() to check if it is successful or not.


Update:

So it seems there's more to subscribeToTopic, as per @DiegoGiorgini's comment in your previous post:

subscribeToTopic will keep retry on background, but it's tied to your app lifecycle (not to google services, yet). So if your app is killed it will stop retrying until the app is open again. (the action is stored so it will be resumed when the app is started again)

The way I was trying out before was after the given period, I will be killing the app and didn't pull it up again.


So I've tried checking this out. It seems that if the device is offline when the request for subscription is sent, it will re-try for a period of time (20-30 seconds or so?) then will stop if still not connected. The request probably reached a time-out error. But since there is no return value for subscribeToTopic(), there is no way for you to determine this via your client app. You can send in a Feature Request if you want, pertaining to this.

However, as of the moment, an approach I think that you could do is to have a checker in your client app, where if only the device is online will you send the request.

You can also check it via your app server as I've mentioned in your previous post.

like image 120
AL. Avatar answered Oct 05 '22 22:10

AL.