我将第一个屏幕传递的数据为:
/** Start Events Schedule screen **/
private fun startEventScheduleForTodaysEvents(eventCode: String?) {
val eventsIntent = Intent(this, ActEventSchedule::class.java)
intent.putExtra(Keys.EVENT_CODE,"data")
startActivity(eventsIntent)
}
第二个屏幕,我收到的数据为:
/** Get data from previous screen **/
private fun getDataFromPrevScreen() {
val extras = intent.extras
if (extras != null) {
eventCode = extras.getString(Keys.EVENT_CODE)
}
}
我无法接收数据
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.act_event_schedule)
//Get data from previous screen
getDataFromPrevScreen()
}
答案 0 :(得分:0)
您要传递一种意图并将数据添加到不同的意图
val eventsIntent = Intent(this, ActEventSchedule::class.java)
intent.putExtra(Keys.EVENT_CODE,"data") // You are adding data to intent
startActivity(eventsIntent) // you are passing events Intent
您的代码应如下
val eventsIntent = Intent(this, ActEventSchedule::class.java)
eventsIntent.putExtra(Keys.EVENT_CODE,"data")
startActivity(eventsIntent)