我正在尝试创建一个初始屏幕,以检查用户是否已经注册,然后启动适当的活动,但该应用程序卡在初始屏幕上而没有任何错误。
public class SplashScreenActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FirebaseAuth mAuth = FirebaseAuth.getInstance();
int SPLASH_TIME_OUT = 1000;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
FirebaseAuth.AuthStateListener mAuthStateListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user == null) {
startWelcomeActivity();
SplashScreenActivity.this.finish();
} else {
startMainActivity();
SplashScreenActivity.this.finish();
}
}
};
}
}, SPLASH_TIME_OUT);
}
private void startMainActivity() {
Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
startActivity(intent);
}
private void startWelcomeActivity() {
Intent intent = new Intent(SplashScreenActivity.this, WelcomeActivity.class);
startActivity(intent);
}
}