Implementation of kotlin anko page jump with parameters or flag

  • 2021-11-29 08:37:38
  • OfStack

1: Normal jump

startActivity < RegisterActivity > ()

Carrying parameters

startActivity < ResetPwdActivity > ("key" to "Value")

2: When the A page jumps to the B page, then to the C page, and then to the A page, it is required to empty the B page, exit the C page, and do not repeat the life cycle of A

startActivity(intentFor < MainActivity > ().singleTop().clearTop())

3: When the A page jumps to the B page, then jumps to the C page, then jumps to the A page, the B page is required to be emptied, the C page exits, and the life cycle of the A is revisited

startActivity(intentFor < MainActivity > ().clearTask().newTask())

4: A page- > B page- > C page- > D page, destroy the three pages of A. B. C, D page in the whole stack

startActivity(intentFor < LoginActivity > ().newTask().clearTask())

The above functions have been tested for ok, and related dependency integration has been omitted.

Supplementary knowledge: kotlin Activity jump and data transmission

1 Define newInstance and define several parameter names in the interface to jump to


 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 in the use of jump interface to send relevant data in

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

3 When you want to jump to the interface definition, use kotlin and accept it simply


 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) }

Related articles: