Check Mobile App
Read now
Start a Project

FirebaseInstanceIdService class is now Deprecated


FirebaseInstanceIdService is a class provided by Google to handle the Firebase Instance ID token refresh events. This class is basically used to get the new refreshed token every time it is generated. As per the documentation we need to override a function called onTokenRefresh() which provided the new device token which can be used to send a notification to that particular device.

Recently, When I was working with the firebase push notification. I updated the dependency version to the latest and found that there are some changes in the implementation of “FirebaseInstanceIdService” class. Google has deprecated the class. So how you will get the refreshed token now. Let us see how you can.

How to get the refreshed token

To receive the notifications you already create a class extending FirebaseMessagingService class and in its onMessageReceived() function, you get the all the data from notification and can use it as you want. Now Google has introduced another function in the FirebaseMessagingService class called onNewToken() and it works just like onTokenRefresh(). On the generation of a new token onNewToken() is called and provides the refreshed token. You can perform the same task in onNewToken() that you previously did in onTokenRefresh().

An example of the above theory can be seen in the below provide code snippet.


How to get the token anywhere in the app

Previous, We used FirebaseInstanceId.getInstance().getToken() to get the current token but this method is deprecated. To get the token, you need to make some changes like the below-given code.

By doing these changes, you can start working with the latest version of the firebase dependencies.

Thank you very much. This is Vedesh Kumar signing off.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


  • Bahaa Salah
    helpful.. thank you
    • Vedesh Kumar (Moderator)
      You’re welcome
  • css.php

    When I think in getting solutions for my Ecommerce Platform, I think of Webkul. They have been such a blessing in our business. We have spent thousands of dollars in support and modules from them. We love their support team. They work very closely with us, and they always go the extra mile when we need help.

    Michael Urresta

    Michael Urresta

    Talk to Sales


    Live Chat
    Start a Project

      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home