Android Studio/ReviewMate

[Android Studio/Kotlin] Transaction시 메세지 전달 방법

kangchaewon 2023. 12. 6. 01:13

 

public fun loadFragment(fragment: Fragment, message : String? = null) {
    val bundle = Bundle()
    bundle.putString("message", message)
    fragment.arguments= bundle

    val transaction =supportFragmentManager.beginTransaction()
    transaction.replace(R.id.main_layout, fragment)
    transaction.addToBackStack(null) // Optional: Add the fragment to the back stack
    transaction.commit()
}

⇒ 번들에 넣어준다 끝

val message = *arguments*?.getString("message")

⇒ 가져오는 법