Delete Firebase Messaging token on Android when device offline

Viewed 379

I'm implementing the logout procedure of my Android Mobile application. In particular I want to delete the Firebase Cloud Messaging Token when the user logs out from the app.

To do so I have implemented a method called revokeFirebaseToken which internally uses the FirebaseMessaging API to delete the token as follows:

 private Task<Void> revokeFirebaseToken() {
    // This will probably throw a onNewToken message
    return FirebaseMessaging.getInstance().deleteToken();
}

In particular this the FirebaseMessagin deleteToken returns a Task which is asynchronously completed by Firebase. I handle the result with an onCompleteListener as follows:

revokeFirebaseToken().addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        //some logic
                    } else {
                        //other logic
                    }
                }
            });

If the application is online everything works well. The problem raises when for some reasons the application is offline; in this scenario the deleteToken raises an exception during the Task execution.

Is there a way to let the revoking token procedure working when device is offline? (Maybe I'm missing something in the Firebase configuration files)

Thanks a lot for any suggestion.

0 Answers
Related