Android 如何使.getCurrentUser()返回非null?
.getCurrentUser()在我重新启动应用程序时不会返回非null值,因此我会停留在MainActivity中,而不是被转移到LogIn.class。也就是说,我一直在登录firebase 我已尝试连接AuthStateListener,但似乎无法解决问题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
@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,则必须提前调用它