[英]How to get around passing data models to fragment arguments to avoid Transaction Too Large Exception?
I'm trying to fix TransactionTooLarge
exceptions.我正在尝试修复
TransactionTooLarge
异常。 I can't find any main culprits in onSaveInstanceState
.我在
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.
感觉很难避免通过这些。
Convert Data Models to JSON and pass it or store it as String.将数据模型转换为 JSON 并将其传递或存储为字符串。 I had faced a similar kind of issue, I had implemented the same way
我遇到过类似的问题,我以同样的方式实施
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尝试通过 viewModel 使用中间人作为 ViewModel,您可以在片段和活动之间附加相同的数据源,并能够顺利更新数据
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.