How to get around passing data models to fragment arguments to avoid Transaction Too Large Exception?

I'm trying to fix TransactionTooLarge exceptions. I can't find any main culprits in onSaveInstanceState.

However, when it comes to passing things to intents and bundles, I am seeing a lot of the follow type of code on a fragment.

companion object {

    fun newInstance(item1: Item1, item2: Item2): MyFragment {
        val fragment = MyFragment()
        val args = Bundle()
        args.putParcelableArrayList(ITEM_1_KEY, item1)
        args.putInt(ITEM_2_KEY, item2)
        fragment.arguments = args
        return fragment
    }
}

Essentially there's a bunch of code passing data models everywhere.

How do you get around trying to pass smaller objects in bundles to fragments?

These fragments basically just pick these up and use them. It feels difficult to avoid passing these through.

1 answer

  • answered 2021-11-29 05:36 Ahmed Karam

    Try to use middle man as ViewModel by viewModel you can attach same source of data between fragment and activity with the ability to update the data smoothly

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum