使用putExtra()传输大量数据到活动; [英] Transferring large amounts of data to Activity using putExtra();
问题描述
应用程序通过(解析后约150对象
JSON
格式),通过大量的对象intent.putExtra();
其中有连载
的对象。
并打开一个新的活动的过程需要2秒左右...
有没有一种方法,以加快这一进程?
The application passes large number of objects (about 150 objects after parsing JSON
format) via intent.putExtra();
Among them are serialized
objects.
And the process of opening a new activity takes about 2 seconds...
Is there a way to speed up this process?
推荐答案
如果你只是想从一个活动的数据传递到另一个你可以只使用一个静态变量,它是从两个活动的访问。这样就无需序列化和反序列化的所有对象。例如:
If you just want to pass data from one activity to another you can just use a static variable that is accessible from both activities. This eliminates the need to serialize and deserialize all the objects. Example:
public class Globals {
public static List<MyObject> myObjects;
}
在一个活动,您可以设置要在 Globals.myObjects
来传递数据和接收活动可以从那里得到它。
In one activity you can set the data you want to pass in Globals.myObjects
and the receiving activity can get it from there.
请注意,这个机制确实有一些缺点(比如Android的时候你杀死的过程和以后重新启动它)。然而,这可以是至少麻烦的方法来简单地大量从一个活动对象的手到另一
Be aware that this mechanism does have some drawbacks (like when Android kills your process and restarts it later). However, this can be the least troublesome way to simply hand a lot of objects from one activity to another.
这篇关于使用putExtra()传输大量数据到活动;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!