I'm unsure how to handle different user accounts on the same device appropriately, as Firebase only creates one Instance-Id per device.
Therefore, I thought that it would be possible to delete the Instance-Id when the user is logged out and to create a new one when a new user is logged in.
On login:
FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(task -> System.out.println(task.getResult().getToken()));
On logout:
FirebaseInstanceId.getInstance().deleteInstanceId()
Does Firebase ensure that the Instance-Id will be unique, even if it is generated multiple times on the same device? The reasons why I prefer this approach are that it's simple to unsubscribe the user from all topics at once and moreover push notifications can be addressed to a specific user.