Reputation: 25
I am not getting data which i passed from another Activity using intent.putExtra. Overall it is also not showing errors. I am new to Android and Kotlin
Activity One
i2.setOnClickListener(View.OnClickListener {
var i = Intent(this,Courses::class.java)
i.putExtra("semester",'2')
startActivity(i)
})
Activity Two
var semester:String? = null
semester = intent.getStringExtra("semester")
Not getting any data Just null and also not getting error. I tested it to show using Toast
Upvotes: 0
Views: 71
Reputation: 1119
Try like this, it should work.
i2.setOnClickListener(View.OnClickListener {
Intent i = new Intent(this,Courses.class)
i.putExtra("semester",'2')
startActivity(i)
})
In second activity try this in OnCreate method:
Intent intent = getIntent();
savedInstanceState = intent.getExtras();
char exampleVariable = savedInstanceState.get("semester");
Upvotes: 0