V
V
Valera Programmer2016-02-26 12:52:37
Java
Valera Programmer, 2016-02-26 12:52:37

How to transfer an object from one activity to another?

What is the best way to pass an object from one activity to another
1. Pass it through an intent and parse it on another activity.
2. Make it so that a link to the same object is available in different activities.
what will be better?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Denis Zagaevsky, 2016-02-26
@noddux

1) Pass through Intent Parcelable/Serializable. Suitable for simple small objects, not suitable for large or lists - too expensive.
2) Put in the database, transfer the primary key (or selection criteria) through the Intent - convenient, scalable.
3) Store in static fields - try to avoid this. The reason is the re-creation of the entire application when there is not enough memory, in this case, restoring such a static state is a separate difficult task.

I
Ilya Pavlovsky, 2016-02-26
@TranE91

1. Serializable / Parcelable
2. Singleton

O
Oleg Gamega, 2016-02-26
@gadfi

2. Make it so that the link to the same object is available in different activities.
in our area for such a thing, not only they beat the face, they don’t even say hello afterwards
1) Parcelable is the fastest way, but you need to write an implementation (there are plugins that will do it for you)
2) Serializable is slower than Parcelable but does not require extra gestures
3) in the form of a json string, for example, using Gson (there are essentially no advantages, but if there is already a ready-made in models, why not)

T
Timur Sergeevich, 2016-02-26
@MyAlesya

I don't know how android works. But it seems to me to just pass the link and that's it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question