Passing a function or a lambda as parameter to DialogFragment via Navigation safe args

Viewed 324

Can we pass a function or a lambda by putting parcelable object and then to get it from dialog fragment? For example,

@Parcelize
class ProfilResimListener (val loadProfilResimLambda: (uri:Uri) -> Unit):Parcelable{
 fun loadProfilResim(uri:Uri) = loadProfilResimLambda(uri)
}

val loadProfilResimLambda: (Uri) ->Unit = ilgiAlanSecili@{ imageUri ->... }

val bundle = bundleOf().apply {
  putParcelable("loadProfilResim",ProfilResimListener(loadProfilResimLambda))
}

findNavController().navigate(R.id.resimSecBottomSheetDialogFragment,bundle)

This is getting java.lang.RuntimeException: Parcelable encountered IOException writing serializable object exception. Is there any other way to pass function via navigation safeargs

0 Answers
Related