Issue
I am passing some value through intent from FirstActivity
to MainActivity
. But, when I try to retrieve that value from second activity (i.e. MainActivity) I am not able to do so.
FirstActivity
var i = Intent()
launcher?.launch(Intent(this, MainActivity::class.java))
i.putExtra("key", cold)
startActivity(i)
MainActivity
val initialCold = intent.getStringExtra("key")
Solution
Your problem is in this line launcher?.launch(Intent(this, MainActivity::class.java))
this is another intent, not i
and you launched it without the extra key string, so you can't get it in your MainActivity, the right way if you want to launch activity for result
val intent = Intent(this, MainActivity::class.java)
intent.putExtra("key", cold)
launcher?.launch(intent)
Or like this if you want to start the MainActivity without result
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
Answered By - AmrDeveloper
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.