-2

I'm trying to send a user to an activity based off of if their email is verified and then if they have a username. My code looks like this so far:

if (isEmailVerified == true) {                                                    
    if (user.displayName == null) {                                                        
        startIntent(NewUserLayoutProfile)
        } else {
         startIntent(MainActivity)
    }
}
if (isEmailVerified == false) {                                                    
startIntent(ResendEmailVerification)
}

And

private fun startIntent (theIntent: Activity) {

            val i = Intent(this, theIntent::class.java)
            startActivity(i)
    }

How do I pass across the activity? I tried passing it as a String and that didn't work. What am I doing wrong here?

JediBurrell
  • 1,069
  • 10
  • 24
Jeff McBride
  • 73
  • 12
  • 1
    you have to pass the `::class.java` like `MainActivity::class.java` to the function, the parameter can be `theIntent: Class<*>` – Tim Sep 17 '18 at 09:20
  • Please add this as an answer so I can credit you for the answer. – Jeff McBride Sep 17 '18 at 09:47
  • Possible duplicate of [Kotlin Android start new activity](https://stackoverflow.com/questions/45518139/kotlin-android-start-new-activity) – JediBurrell Sep 17 '18 at 10:07
  • No, that question is sending the intent to a method. Plus it is adding a `.putExtra` to the intent. Not at all the same thing. – Jeff McBride Sep 17 '18 at 10:59

1 Answers1

0

Here's the proper code tha works in Kotlin:

if (userInfo?.isEmailVerified == false) {
                                        startIntent(ResendEmailVerification::class.java)
                                    } else {
                                        if (userInfo?.displayName != null) {
                                            startIntent(MainActivity::class.java)
                                        } else {
                                            startIntent(NewUserLayoutProfile::class.java)
                                        }
                                    }

And

private fun startIntent (theIntent: Class<*>) {

            val i = Intent(this, theIntent)
            startActivity(i)
    }
Jeff McBride
  • 73
  • 12