KtKit icon indicating copy to clipboard operation
KtKit copied to clipboard

startActivity

Open aowoWolf opened this issue 2 years ago • 3 comments

with(Intent(context, targetClass)) { params().forEach { makeParams(it) } this } 就简单两个问题:

  1. forEach装箱拆箱问题
  2. 不用with,用apply不是更好?最后返回就不用写this

aowoWolf avatar Sep 18 '21 06:09 aowoWolf

package androidx.core.os

public fun bundleOf(vararg pairs: kotlin.Pair<kotlin.String, kotlin.Any?>): android.os.Bundle

关于Fragment,不是有现成的bundleOf方法吗?

aowoWolf avatar Sep 18 '21 06:09 aowoWolf

with(Intent(context, targetClass)) { params().forEach { makeParams(it) } this } 就简单两个问题:

  1. forEach装箱拆箱问题
  2. 不用with,用apply不是更好?最后返回就不用写this

感谢你的反馈

forEach 确实存在 装箱拆箱问题,还会生成临时对象,会跟着下次的版本一起修复 确实 apply 比 with 会更好些

hi-dhl avatar Sep 18 '21 10:09 hi-dhl

package androidx.core.os

public fun bundleOf(vararg pairs: kotlin.Pair<kotlin.String, kotlin.Any?>): android.os.Bundle

关于Fragment,不是有现成的bundleOf方法吗?

从写法上少一点步骤,例如 bundleOf

val bunlde = bundleOf(
    KEY_USER_NAME to "ByteCode",
    KEY_USER_PASSWORD to "1024",
    KEY_PEOPLE_PARCELIZE to PeopleModel("hi-dhl")
)
LoginFragment().arguments = bunlde

hi-dhl avatar Sep 18 '21 10:09 hi-dhl