'Starting an activity opens a blank activity

So I have two activities. MainActivity (login) and GoogleSignInActivity which is where I'm handling the whole GoogleSignIn (with Firebase) process.

The problem:

Everything seems to be working fine, however, when I click the "Login" button, it seems like there's another blank activity opening with the Google Dialog (where I have to choose my account).

See this: image #1

The expected behavior:

I want that googleSignIn window to be opened in the MainActivity (login).

What I tried so far:

I was hoping that the activity will simply not show by doing removing the setContentView() but that's not helping. The blank activity keeps showing.

    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    //setContentView(R.layout.activity_google_sign_in);
 
    val googleSignInOptions =
        GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken("26905381813-ffff.apps.googleusercontent.com")
            .requestEmail()
            .build()

    firebaseAuth = FirebaseAuth.getInstance()
    println(" ${firebaseAuth.currentUser}");
   

    googleSignInClient = GoogleSignIn.getClient(this, googleSignInOptions)
    val intent = googleSignInClient.signInIntent
    startActivityForResult(intent, 100)

Now, if I set the above 'setContentView' to MainActivity, I'll get the desired behavior, but the user will notice that a new LOGIN window has opened.

What would you suggest? I tried to set the theme to Theme.NoDisplay but that's crashing the application.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source