K
K
Koshkasobaka2021-07-04 18:28:40
Android
Koshkasobaka, 2021-07-04 18:28:40

How to pass object between fragments using FragmentResult?

Sending:

binding!!.bClose.setOnClickListener {
                    val note = Note(title, content, position)
                   setFragmentResult(
                       Constants.SAVE_EDIT,
                        bundleOf(
                         "keyNote" to note 
                       )
                   )
                   activity?.onBackPressed()
                }


I accept:
setFragmentResultListener(Constants.SAVE_EDIT) { key, bundle ->
            val note = bundle.getSerializable("keyNote")   
          }


But the object is not recognized as belonging to the Note class and it is not possible to access its fields. Tell me, please, how to be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-07-05
@Koshkasobaka

how to be?

Learn the language you write in. Well, read the documentation .
The method returns a Serializable, how do you think it should be "recognized"? You need to cast to your type. as note.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question