一、从MainActivity中跳转到AnotherActivity
val btnSubmit = findViewById
二、从MainActivity跳转到AnotherActivity,并传递 数据
方式一:
val btnSubmit = findViewById
方式二:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val btnSubmit = findViewById
三、在AnotherActivity中接受数据
class AnotherActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_another)
val keyValue1 = intent.getStringExtra("key1")
val keyValue2 = intent.getDoubleExtra("key2",0.0)
Log.i("AnotherActivity", "keyValue1 is "+keyValue1)
Log.i("AnotherActivity", "keyValue2 is "+keyValue2)
}
}
运行结果:



