I have a fragment and I create a new Instance of it, in my Activity, Also I'm passing a Parcelable data class to the fragment like this:
fun newInstance(
use: User,
date: Date
): CalendarDialogFragment {
val fragment = MyFragment()
val bundle = Bundle()
bundle.putParcelable("user", user)
bundle.putSerializable("date", date)
fragment.arguments = bundle
return fragment
}
And in the fragment I want to use it like this:
var user = arguments?.getParcelable("user")
var date = arguments?.getSerializable("date")
This is a normal way of passing data to fragments.
because of shallow copy, When I change this user object and update its field in the fragment, the bundle object will be updated too.
But for some objects like the Date
(java.util) type, it's not happening. For example, if I pass a Date
to the fragment and do the same, the bundle object of date will not update like the user object, I think I'm missing something here!?