title: Why do we have to call getCurrentUser() several times Firebase?
body: <p>I am creating a Journal app.</p>
  <p>I am currently working on the functionality for if the user is already logged in—bypass the &quot;get started/log in activities&quot;</p>
  <p>In the video I am watching to create a journal app, the instructor calls
  <code>mUser = firebaseAuth.getCurrentUser();</code> several times.</p>
  <p>He calls it in <code>onStart()</code>, in <code>onCreate()</code> and in <code>onAuthStateChanged()</code>. I can understand why we might need to call it again in <code>onAuthStateChanged()</code>, but in this case, I'm just checking if the user is already logged in, so it shouldn't change from the user received in <code>onCreate()</code></p>
  <p>I removed it from <code>onAuthStateChanged()</code> and <code>onStart()</code> and everything is still working fine. However, I'm unsure if it will lead me to errors in the future. If anyone can confirm this, I would appreciate it.
  <strong>Is there a reason why we need to call <code>getCurrentUser()</code> several times?</strong>
  Thanks.</p>
  <p>This is my full code for reference:</p>
  <pre><code>public class MainActivity extends AppCompatActivity {
      Button getStarted;
  
      private FirebaseUser mUser;
      private FirebaseAuth firebaseAuth;
      private FirebaseAuth.AuthStateListener myListener;
      private FirebaseFirestore db = FirebaseFirestore.getInstance();
      private CollectionReference myCollectionRef = db.collection(&quot;Users&quot;);
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          firebaseAuth = FirebaseAuth.getInstance();
          mUser = firebaseAuth.getCurrentUser();
  
  
  
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          getStarted = findViewById(R.id.btnGetStarted);
  
          getStarted.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  startActivity(new Intent(MainActivity.this, LoginActivity.class));
                  finish();
              }
          });
  
          myListener = new FirebaseAuth.AuthStateListener() {
              @Override
              public void onAuthStateChanged(@NonNull @NotNull FirebaseAuth firebaseAuth) {
                  if(mUser != null){
                      //logged in
                      
                      //I commented this out and everything is still working fine
                      //mUser = firebaseAuth.getCurrentUser();
                      String currentUserId = mUser.getUid();
  
                      myCollectionRef.whereEqualTo(&quot;userId&quot;, currentUserId).addSnapshotListener(new EventListener&lt;QuerySnapshot&gt;() {
                          @Override
                          public void onEvent(@Nullable @org.jetbrains.annotations.Nullable QuerySnapshot value, @Nullable @org.jetbrains.annotations.Nullable FirebaseFirestoreException error) {
                              if(error != null){
                                  Log.d(&quot;my_error&quot;, error.toString());
  
                              }
  
                              if(!value.isEmpty()){
                                  for(QueryDocumentSnapshot snapshot : value){
                                      JournalApi myJournalApi = new JournalApi();
                                      myJournalApi.setUsername(snapshot.getString(&quot;username&quot;));
                                      myJournalApi.setId(snapshot.getString(&quot;userId&quot;));
  
                                      startActivity(new Intent(MainActivity.this, JournalList.class));
  
                                      finish();
                                  }
                              }
                          }
                      });
                  }else{
                      //not logged in
                  }
              }
          };
  
  
      }
  
      @Override
      protected void onStart() {
          super.onStart();
  
          //I commented this out and everything is still working fine
          //mUser = firebaseAuth.getCurrentUser();
          firebaseAuth.addAuthStateListener(myListener);
      }
  
      @Override
      protected void onPause() {
          super.onPause();
  
          if(firebaseAuth != null){
              firebaseAuth.removeAuthStateListener(myListener);
          }
      }
  }
  </code></pre>