完善 ActivityExt,支持传递单个 Pair
This commit is contained in:
parent
4f6be6b503
commit
f1decbeb5b
|
|
@ -36,21 +36,25 @@ class ActivityExtActivity : BaseActivity() {
|
|||
}
|
||||
|
||||
startActivityWithValue.setOnClickListener {
|
||||
startKtxActivity<AnotherActivity>(value = "string" to "single value")
|
||||
}
|
||||
|
||||
startActivityWithMultiValue.setOnClickListener {
|
||||
startKtxActivity<AnotherActivity>(
|
||||
values = arrayListOf(
|
||||
"int" to 1,
|
||||
"boolean" to true,
|
||||
"string" to "from previous activity"
|
||||
)
|
||||
"string" to "multi value"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
startActivityWithBundle.setOnClickListener {
|
||||
startKtxActivity<AnotherActivity>(
|
||||
extra = Bundle().apply {
|
||||
putInt("int",2)
|
||||
putBoolean("boolean",true)
|
||||
putString("string","from bundle")
|
||||
putInt("int", 2)
|
||||
putBoolean("boolean", true)
|
||||
putString("string", "from bundle")
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,11 @@
|
|||
android:text="startActivityWithValue"
|
||||
style="@style/NormalButton"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/startActivityWithMultiValue"
|
||||
android:text="startActivityWithMultiValue"
|
||||
style="@style/NormalButton"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/startActivityWithBundle"
|
||||
android:text="startActivityWithBundle"
|
||||
|
|
|
|||
|
|
@ -14,6 +14,13 @@ import java.io.Serializable
|
|||
inline fun <reified T : Activity> Activity.startKtxActivity(flags: Int? = null, extra: Bundle? = null): Unit =
|
||||
startActivity(getIntent<T>(flags, extra))
|
||||
|
||||
inline fun <reified T : Activity> Activity.startKtxActivity(
|
||||
flags: Int? = null,
|
||||
extra: Bundle? = null,
|
||||
value: Pair<String, Any>?
|
||||
): Unit =
|
||||
startActivity(getIntent<T>(flags, extra, arrayListOf(value)))
|
||||
|
||||
inline fun <reified T : Activity> Activity.startKtxActivity(
|
||||
flags: Int? = null,
|
||||
extra: Bundle? = null,
|
||||
|
|
|
|||
Loading…
Reference in New Issue