1
public class MyFirebaseInstanceService extends FirebaseMessagingService
{
    @Override
    public void onNewToken(String s) {
        super.onNewToken(s);

        Log.d("DTAG","onNewToken: "+s);
    }
}

And in MainClass:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener( MainActivity.this,  new OnSuccessListener<InstanceIdResult>() {
        @Override
        public void onSuccess(InstanceIdResult instanceIdResult) {
            String newToken = instanceIdResult.getToken();
            Log.d("DTAG","Token Main: "+newToken);

        }
    });
}

When I run my app first time the output that I get is:

D/DTAG: Token Main: token_a
D/DTAG: onNewToken: token_b

The second time I get:

D/DTAG: Token Main: token_a

Please help me get this...

 1. If I run for the first time, from where is gets token in MainClass (token_a)
 2. In case the token is renewed (onNewToken) which is token_b, why I still keep seeing token_a when launching the app in second time and what happened to token_b?
Dim
  • 4,527
  • 15
  • 80
  • 139
  • check this answer you will get idea how `onTokenRefresh/onNewToken` is work https://stackoverflow.com/a/51835126/7666442 – AskNilesh Nov 01 '18 at 10:40
  • Ok, but the thing is, onNewToken returns token "a", and when launching the app on second time at mainClass i see it`s token "b". Should not it need to be replaced? – Dim Nov 01 '18 at 10:45

0 Answers0