lordmegamax lordmegamax - 3 months ago 11
JSON Question

Transferring large amounts of data to Activity using putExtra();

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?

Answer

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;
}

In one activity you can set the data you want to pass in Globals.myObjects and the receiving activity can get it from there.

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.

Comments