import com.google.firebase.auth.FirebaseUser;
/**
* Loading screen activity
*/
public class SplashActivity extends AppCompatActivity {
private FirebaseUser currentUser;
Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
handler=new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if ( currentUser != null ) {
Intent intent=new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
finish();
} else {
Intent intent = new Intent(SplashActivity.this, StartActivity.class);
startActivity(intent);
finish();
}
}
},3000);
}
}
I did this code
if ( currentUser != null ) {
But the above code didn’t seem to work, it always run this StartActivity.class
Unless the currentUser function is not working
2
Answers
You’ve forgotten to initialize your
currentUser
variable. From the Firebase documentation on getting the current user on Android:You need to initialize FirebaseAuth to get the credentials with FirebaseUser variable.