Sobes.tech
Junior — Middle

Are the arguments passed to a fragment preserved when transitioning between different states?

sobes.tech AI

Answer from AI

Arguments passed to a fragment via setArguments(Bundle) during creation are stored in its Bundle and are accessible after the fragment is recreated by the system, for example, during a configuration change. However, these arguments are immutable — they cannot be changed after being set. If you need to preserve mutable data across state changes, you should use state-saving methods (onSaveInstanceState) or ViewModel.

Example of setting arguments:

val fragment = MyFragment().apply {
    arguments = Bundle().apply {
        putString("key", "value")
    }
}

Thus, arguments are stored by the system and accessible after fragment restoration, but are not intended for storing mutable data during the lifecycle.

Are the arguments passed to a fragment preserved when… - sobes.tech