FirebaseUser user = firebaseAuth.getCurrentUser(); assert user != null; 

And what does assert mean?

 FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); 
  • one
    And where firebaseAuth variable firebaseAuth ? If it is taken as FirebaseAuth firebaseAuth = FirebaseAuth.getInstance() , then there will be no difference. The design of assert pulls on a separate question. - Regent
  • assert: habrahabr.ru/post/141080 - gil9red

1 answer 1

Absolutely no difference. To get a FirebaseAuth object, you need to call the static getInstance() method. Correspondingly, the difference between FirebaseUser user = firebaseAuth.getCurrentUser(); and FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); only that in the first case we save the object into a variable and in the second there is no.

Assert - not sure where you got it from, but its Java equivalent will look like this

 if (user != null) { // User is signed in Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid()); } else { // User is signed out Log.d(TAG, "onAuthStateChanged:signed_out"); } 

Assert from eng. to expect. Accordingly, we need this check in order to continue to perform actions on this variable.