ijann
ijann

Reputation: 111

The Intent of the FirebaseUI is destroyed with the onBackPressed () method, how to prevent from destroying?

my problem is that I use 2 activities, but this problem focuses on the first activity, the A this activity is blank ok. I'm using FirebaseUI, when I start the App, shows me the login options, This is generated by the Auth.getInstance () intent ok I show you the code of the method.

private fun authenticateUser() {
    startActivityForResult(
        AuthUI.getInstance()
            .createSignInIntentBuilder()
            .setTheme(R.style.CustomTheme)
            .setLogo(R.drawable.firelogo)
            .setAvailableProviders(getProviderList())
            .setIsSmartLockEnabled(true)
            .build(),
        REQUEST_CODE)
}

when I press onBackPressed (), this method destroys the attempt generated by FirebaseUI, and it shows me activity A, which is blank, If I press "Back" again, it shows me again the intent of FirebaseUI. okay

I want to avoid pressing "Back" when I'm on the FirebaseUI screen

I do not know if you understand the problem that I have.

There are 2 images, the first one is generated by FirebaseUI, the second is activity A, which is blank. If I press "Back" I see activity A, blank, if I press again, it generates the activity of FirebaseUI

https://i.sstatic.net/0mWIX.jpg

the onBackPressed() method I have it like this

override fun onBackPressed() {
    if(currentUser == null) {
        authenticateUser()
    }
}

The problem is, I do not know how to prevent it from being destroyed the activity generated by FirebaseUI. caused by the onBackPressed() method. This activity is generated by the Intent AuthUI.getInstance()....

startActivityForResult(
    AuthUI.getInstance()
        .createSignInIntentBuilder()
        .setTheme (R.style.CustomTheme)
        .setLogo (R.drawable.firelogo)
        .setAvailableProviders(getProviderList())
        .setIsSmartLockEnabled(true)
        .build(),
    REQUEST_CODE)

Upvotes: 0

Views: 486

Answers (1)

ijann
ijann

Reputation: 111

Well, answering my question. This has to do with the life cycle of the activity, so what I did was:

override fun onBackPressed() {
        onRestart()
}

override fun onRestart() {
    currentUser = null
    if (currentUser == null) {
        startActivity(Intent(this, FirebaseAuthActivity::class.java))
        finish()
    }
    super.onRestart()
}

Upvotes: 1

Related Questions