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

353 Views Asked by At

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

There are 1 best solutions below

0
On

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