Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使.getCurrentUser()返回非null?_Android_Firebase_Firebase Authentication - Fatal编程技术网

Android 如何使.getCurrentUser()返回非null?

Android 如何使.getCurrentUser()返回非null?,android,firebase,firebase-authentication,Android,Firebase,Firebase Authentication,.getCurrentUser()在我重新启动应用程序时不会返回非null值,因此我会停留在MainActivity中,而不是被转移到LogIn.class。也就是说,我一直在登录firebase 我已尝试连接AuthStateListener,但似乎无法解决问题 @Override protected void onStart() { super.onStart(); FirebaseUser user = FirebaseAuth.getInstance().getCurr

.getCurrentUser()在我重新启动应用程序时不会返回非null值,因此我会停留在MainActivity中,而不是被转移到LogIn.class。也就是说,我一直在登录firebase

我已尝试连接AuthStateListener,但似乎无法解决问题

@Override
protected void onStart() {
    super.onStart();

    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    if(user == null){
        Intent intent = new Intent(MainActivity.this, LogIn.class);
        startActivity(intent);
        finish();

    } else{

    }
  }

用户保持登录状态,直到您呼叫。因此,如果希望getCurrentUser返回null,则必须提前调用它