简体   繁体   English

Android MVP - 从活动展示器到片段展示器的数据

[英]Android MVP - Data from activity presenter to fragment presenter

I have an activity with a DialogFragment and I need to pass an ArrayList from the activity presenter to the fragment presenter.我有一个带有 DialogFragment 的活动,我需要将 ArrayList 从活动演示者传递给片段演示者。 Currently I'm doing this within the newInstance method with parameters and by using arguments.目前,我在带有参数的 newInstance 方法中执行此操作,并使用 arguments。

Is there any other method which I should consider?还有其他我应该考虑的方法吗?

If the data is non-persistent, and your using it for a single purpose.如果数据是非持久性的,并且您将其用于单一目的。 Then passing it to the Fragment via newInstance / Builder is fine, I would think of newInstance / Builder s as just a more round-about way of using a constructor.然后通过newInstance / Builder将它传递给Fragment就可以了,我认为newInstance / Builder只是使用构造函数的一种更迂回的方式。

If the data is persistent, you might want to have a service / singleton that the Dialog 's presenter can pull from when needed.如果数据是持久的,您可能希望有一个service / singleton Dialog的演示者可以在需要时从中提取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM