在Kotlin中以编程方式启动一个意图

问题描述 投票:-2回答:1

我正在尝试将用户发送到基于其电子邮件已验证的活动,然后是否具有用户名。到目前为止我的代码看起来像这样:

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

private fun startIntent (theIntent: Activity) {

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

我如何通过活动?我尝试将它作为字符串传递,但是没有用。我在这做错了什么?

android android-intent kotlin
1个回答
0
投票

这是适用于Kotlin的代码:

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

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

            val i = Intent(this, theIntent)
            startActivity(i)
    }
© www.soinside.com 2019 - 2024. All rights reserved.