Reputation: 310
I am calling the activity RegistrationCredentialsActivity from two different activities: RegistrationActivity and ForgotPasswordActivity. I am passing activity name as StringExtra from these activities along with other details. But inside the RegistrationCredentialsActivity, I'm unable to fetch the data sent from ForgotPasswordActivity. Only activity name is fetched successfully.
I'm setting the received data as the text of a TextView of RegistrationCredentialsActivity . Anyone have any idea why this is happening?
P.S: It is working fine for RegistrationActivity, problem is arising only for ForgotPasswordActivity
RegistrationCredentialsActivity(where I'm setting received data to a 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
}
RegistrationActivity:
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)
When called from RegistrationActivity(correct):
When called from ForgotPasswordActivity(incorrect):
Upvotes: 0
Views: 73
Reputation: 1795
it seem that "email" and "mobile" variables passed in the forgot password intent are empty
test this:
val intent = Intent(this@ForgotPasswordActivity,RegistrationCredentialsActivity::class.java)
intent.putExtra("activity","ForgotPassword")
intent.putExtra("email","TEST")
intent.putExtra("mobile","TEST")
startActivity(intent)
you will probably find that in this case TEST will be written..
Then check if you set "email" and "mobile" variables correctly and that they are not empty.
Upvotes: 1