ХабрПостыНовостиМегапосты?

Обновление Android Jetpack: Activity Result API и рефакторинг Fragment

Привет! С вами Android Broadcast. Прошли 2 недели и очередной релиз библиотек Jetpack от Google уже с нами. Вышло долгожданное исправление множества багов в Fragment из-за рефакторинга внутри FragmentManager, Activity Result API и много другого. Все самое интересное вы найдете ниже, а все подробности на сайте

Если вы хотите узнавать про последние новости Android разработки сразу, тогда подпишитесь на Telegram канал Android Broadcast или следите за ними в формате видео на YouTube канале, а также подкасте

Activity 1.2.0

Все изменения здесь

val getContent = registerForActivityResult(GetContent()) { uri: Uri? ->
    // Handle the returned Uri
}

override fun onCreate(savedInstanceState: Bundle?) {
    // ...

    val selectButton = findViewById<Button>(R.id.select_button)

    selectButton.setOnClickListener {
        // Pass in the mime type you'd like to allow the user to select
        // as the input
        getContent.launch("image/*")
    }
}

Fragment 1.3.0

Все изменения здесь

// Fragment1
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    // Use the Kotlin extension in the fragment-ktx artifact
    setFragmentResultListener("requestKey") { requestKey, bundle ->
        // We use a String here, but any type that can be put in a Bundle is supported
        val result = bundle.getString("bundleKey")
        // Do something with the result
    }
}
// Fragment 2
button.setOnClickListener {
    val result = "result"
    // Use the Kotlin extension in the fragment-ktx artifact
    setFragmentResult("requestKey", bundleOf("bundleKey" to result))
}

Lifecycle 2.3.0

Все изменения здесь

SavedState 1.1.0

Все изменения здесь

Core Role 1.0.0

Все изменения здесь

@kirich1409
11.02.2021 15:28 UTC
Первоисточник