0

I am trying to redirect user directly to home screen without showing login screen to users. For this I wrote this code,

    @Override
        protected void onStart() {
            super.onStart();
            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            if (user != null){
                startActivity(new Intent(LoginActivity.this,MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK));
            }
        }

This code works but when I open the app at first it shows my login activity for some second and then redirect to Main activity. But I don't want to show that login activity any more if user already log in.

Here is my screen record: https://youtu.be/j1jsVXwDZtA

Anindra
  • 11
  • 4

1 Answers1

0

In the loginActivity the method oncreate() is executed first, then the onStart() method. So, a instance of loginActivity is created first, then it redirects to your mainActivity. That's why you see the loginActivity. Do the check in your MainActivity and use your MainActivity as your launch activity.

Mike087
  • 486
  • 3
  • 13