简体   繁体   English

在活动之间传递 Future 对象

[英]Passing Future object between activities

Coming from Java EE to an Android application (i'm not Guru in Java EE), For a fatest load of the application, we decided to process a files asynchronously, when the application starts, we launch some asynchronous channels to read the files, then we open the main activity, the idea is the user may not go directly to the use cases which need these files, but if he go it direclty and the asynchronous read wasn't terminated, he should wait a while(what the client wanted).从 Java EE 到 Android 应用程序(我不是 Java EE 中的 Guru),为了应用程序的最大负载,我们决定异步处理文件,当应用程序启动时,我们启动一些异步通道来读取文件,然后我们打开主活动,想法是用户可能不会直接进入需要这些文件的用例,但是如果他直接进入并且异步读取没有终止,他应该等待一段时间(客户端想要什么)。

My question is how to passe the Future object between activities?我的问题是如何在活动之间传递 Future 对象? my team agreed for using static methods or singletons, but i really don't love singleton because its an antipattern and i don't like static methods because they behave nearly like singleton.我的团队同意使用静态方法或单例,但我真的不喜欢单例,因为它是一种反模式,我不喜欢静态方法,因为它们的行为几乎像单例。

Trying to use parceable or serializable, but future doesn't use implement anyone of it, i tried to use RoboGuice (its based on static fields but its busniss) but its a little buggy, how can i do it in android in pretty way, if there's another idea, i will be obliged to use singleton or static methods.尝试使用可解析或可序列化,但未来不使用任何实现,我尝试使用 RoboGuice(它基于静态字段但它的业务)但它有点错误,我如何在 android 中以漂亮的方式做到这一点,如果有其他想法,我将不得不使用单例或静态方法。

EventBus can be used to send objects from 1 place to another (eg asyncTask to Activity). EventBus可用于将对象从一个地方发送到另一个地方(例如 asyncTask 到 Activity)。 It's great and easy to use, and it will accomplish what you're trying to do perfectly.它很棒且易于使用,它将完美地完成您想要做的事情。

You can create your custom object classes to send between almost any 2 classes, Activities, Services, or whatever you with.您可以创建自定义对象类以在几乎任何 2 个类、活动、服务或任何您使用的类之间发送。

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

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