lordmegamax
lordmegamax

Reputation: 2694

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?

Upvotes: 3

Views: 5228

Answers (3)

Muhammad Farhan Habib
Muhammad Farhan Habib

Reputation: 1809

I think using a Singleton class for sharing large amount of temporary data between activities is a great way to go. Keeps it really quick and simple.

Although it can be done through Android Parcelable but it has storage limitation which can cause this error "!!! FAILED BINDER TRANSACTION !!!"

Upvotes: 0

Tobrun
Tobrun

Reputation: 18391

One suggestion could be:

Use parceable where you are using serializable

Another suggestion could be:

Use something else to save/restore the data. e.g. a database

Upvotes: 2

David Wasser
David Wasser

Reputation: 95636

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.

Upvotes: 3

Related Questions