kotlin Activity跳转以及数据传输

 1  在要跳转到界面定义newInstance 并定义几个参数名

 companion object {
       
        private const val KEY_TITLE = "title"
        private const val KEY_SUBTITLE = "subtitle"
        private const val KEY_CAR_ID = "car_id"
        fun newInstance(context: Activity, title: String, id: Int,subtitle: String) {
            context.startActivity<CarListDetailActivity>(KEY_TITLE to title, KEY_CAR_ID to id,KEY_SUBTITLE to subtitle)
        }
    }

2  在使用跳转的界面 传相关数据进去即可

 CarListDetailActivity.newInstance(this,data.number,data.id,collapsing_toolbar_layout.title.toString())

3 在要跳转到界面定义 使用kotlin 使用单利接受即可

   private val subtitle: String by lazy { intent.getStringExtra(KEY_SUBTITLE) }
    private val title: String by lazy { intent.getStringExtra(KEY_TITLE) }
    private val car_id: Int by lazy { intent.getIntExtra(KEY_CAR_ID, -1) }

猜你喜欢

转载自blog.csdn.net/u013297881/article/details/84298905
今日推荐