无法从通用意图中获取数据

我从两个不同的活动中调用Activity RegistrationCredentialsActivity:RegistrationActivity和ForgotPasswordActivity。我将从这些活动以及其他详细信息中将活动名称传递为StringExtra。但是在RegistrationCredentialsActivity中,我无法获取从ForgotPasswordActivity发送的数据。仅活动名称已成功获取。

我将接收到的数据设置为RegistrationCredentialsActivity的TextView的文本。有人知道为什么会这样吗?

P.S:RegistrationActivity正常工作,仅ForgotPasswordActivity出现问题

RegistrationCredentialsActivity(将接收到的数据设置为TextView的位置):

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_registration_credentials)
        text = findViewById(R.id.txtRegDetails)
        var string = ""
        if(intent != null){
            val activity = intent.getStringExtra("activity")
            println("Activity = "+activity.toString())          //this line is printed as expected
            if(activity.contentEquals("RegistrationActivity")) {
                string += "Name: " + intent.getStringExtra("name") + "\n"
                string += "Email: " + intent.getStringExtra("email") + "\n"
                string += "Mobile no.: " + intent.getStringExtra("mobile") + "\n"
                string += "Address: " + intent.getStringExtra("address")
            }
            else if(activity.contentEquals("ForgotPassword")){
                println("Inside else block123")       //this line is also printed
                string += "Email: "+intent.getStringExtra("email")+"\n"   //problem lies in these
                string += "Mobile: "+intent.getStringExtra("mobile")          //two lines
            }
        }
        text.text = string
    }

注册活动:

val intent = Intent(this@RegistrationActivity,RegistrationCredentialsActivity::class.java)
                intent.putExtra("name",name)
                intent.putExtra("email",email)
                intent.putExtra("mobile",mobile)
                intent.putExtra("address",address)
                intent.putExtra("activity","RegistrationActivity")
                startActivity(intent)

ForgotPasswordActivity:

val intent = Intent(this@ForgotPasswordActivity,RegistrationCredentialsActivity::class.java)
            intent.putExtra("activity","ForgotPassword")
            intent.putExtra("email",email)
            intent.putExtra("mobile",mobile)
            startActivity(intent)

从RegistrationActivity(正确)调用时:

enter image description here

从ForgotPasswordActivity调用时(错误):

enter image description here

评论