Gerrard Gerrard - 1 year ago 66
Android Question

What are the problems in using Intent to pass objects from one activity to another

UPDATE: Please see "accepted" solution below

What I have observed is one way is Intent.
There is no other proper recommended way.

For me serialization is required when you want to transfer data over network/ or when we need to retrieve objects after a while. Only used in some specific scenarios. But here what I saw is to use intent together with serialization to simply share/pass some data.

According to spec, intent will act as the glue between activities.
I would also assume that we can pass instructions /small amount of data to next activity.

My question more specifically is about passing data/big data using intents.
Considering that serialization is required when using intents. Is this a good way?

Note: Please consider that ,won't be able to use Parcelable in this specific scenario, since developing a framework independent of android.

Answer Source

Intents should only pass small packets of data. If you need to pass something big, save it to storage or a database, pass an uri through the Intent and then read the data in the receiving Activity.

Passing big data in the intent will cause drastic problems, up to the point of killing your app process (which is very annoying to the user).

There is a process-scope limit of 1MB of data being passed between components. Please keep in mind that this does not mean that you can pass 1MB of data safely, as there may be multiple Intents being processed at a time.

You could also consider using an event bus library, like greenrobot EventBus, but these require a big amount of discipline, as they basically let you pass everything everywhere.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download