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
改用双引号
i.putExtra("semester","2")
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");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.